开发者

Apply styles to a UserControl from within its own Xaml

开发者 https://www.devze.com 2023-01-28 06:04 出处:网络
Is there a way 开发者_JAVA技巧to apply styles (specifically style data triggers) to a UserControl within it\'s own XAML code?You cannot access a Style in xaml within the UserControl\'s resources - you

Is there a way 开发者_JAVA技巧to apply styles (specifically style data triggers) to a UserControl within it's own XAML code?


You cannot access a Style in xaml within the UserControl's resources - you have a few options tho:

  1. Set it in coding in the constructor through Style = FindResource(<name>) as Style
  2. Set it in the Parent control <local:MyUserControl Style="{StaticResource MyStyle}"
  3. Put the style in any Visual control's Resources-property 'up-the-chain' with an empty key and TargetType="{x:Type MyUserControl}"

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消