我有一个用户控件,它只是一个带有如下文本的框:
<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/