如何设置带样式的UserControl的属性?(我读了相关的问题,但没有一个解决了我的问题)
我定义了一个简单的UserControl,如下所示:
<UserControl x:Class="MyProject.RedSquare"
...
Height="10" Width="10" Background="Red">
<Grid>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
我现在可以手动指定此控件的宽度/高度.
但我无法使用样式分配属性.
这不起作用:
<Window.Resources>
<Style x:Key="red" TargetType="{x:Type local:RedSquare}">
<Setter Property="Width" Value="200" />
</Style>
</Window.Resources>
...
<local:RedSquare Style="{StaticResource red}" />
Run Code Online (Sandbox Code Playgroud)
奇怪的行为:我可以用样式修改控件的边距,但所有其他属性都不起作用?
有任何想法吗?