c# - Wpf UserControl 宽度和高度不 Taknig

标签 c# .net wpf

我有一个用户控件,它只是一个带有如下文本的框:

<Border x:Name="box" 
            BorderThickness="0"
            BorderBrush="Black" 
            Background="Black"
            Width="200" Height="200">

    <Label Content="Hello World" 
               Height="65"  Width="400"
               Foreground="White" FontSize="32"
               HorizontalAlignment="Center" VerticalAlignment="Center"
               HorizontalContentAlignment="Center" />
</Border>

当我像这样在主窗口中创建它的实例时...

<local:MyBoxControl Width="1000" Height="1000"/>

宽度和高度在 Border 中定义为 200x200当我希望它是我创建它时提供的 1000x1000。

最佳答案

只需从 Border 元素中删除 Width 和 Height。

关于c# - Wpf UserControl 宽度和高度不 Taknig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9382841/

相关文章:

c# - 使用 TPL 并行运行任务

c# - 简单的 WPF 平移;这段代码很接近但不太正确

c# - 插入日期时间错误

javascript - 同一按钮上的 HttpPost 和事件 Asp.Net Web 表单

c# - 有没有其他方法可以将 Task.Status 设置为 Canceled

c# - 在不使用任何类型的情况下加载许多托管 DLL 是否不好?

c# - 如何在 .net core 上配置 AddAuthorization 以允许多个 token 提供者的角色?

c# - 如何访问 ItemsControl 的子项?

.net - 在 ViewModel 中获取 WPF ListView.SelectedItems

c# - 解析 JSON 以响应现有请求