设置常量大小不是很好 - 只有在需要的时候。无论如何,这里是您的解决方案
<UserControl x:Class="WpfApp1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Width="{Binding ElementName=MyStackPanel, Path=ActualWidth}"
Height="{Binding ElementName=MyStackPanel, Path=ActualHeight}">
<Grid>
<StackPanel Width="350"
Height="350"
x:Name="MyStackPanel"
Background="Blue" />
</Grid>
</UserControl>
非常感谢。它的完美:)祝你有美好的一天! – Sanga
然后标记我的答案请 – Peter