我有一个用户控件,我想在其他项目中使用它。当我直接设置一些值到它的属性时,没有问题:
<local:MyUserControl prop1="val1" prop2="val2">
...
</local:MyUserControl>
但是我无法对其应用样式。我尝试过:
<Window ...>
<Window.Resources>
<Style x:Key="MyUserControlStyle" TargetType="{x:Type local:MyUserControl}">
<Setter Property="prop1" Value="val1"/>
<Setter Property="prop2" Value="val2"/>
</Style>
</Window.Resources>
<Grid>
<local:MyUserControl Style="{StaticResource ResourceKey=MyUserControlStyle}">
...
</local:MyUserControl>
</Grid>
</Window>
我错在哪里了? -谢谢