I have a custom UserControl (e.g. called MyUserControl) with several child controls. I would like to create a UserControl.Resources with set of styles and dependency properties assignments for design purposes (without styles the control looks like a ball of mud). Later I will comment that styles.
The problem is, that I don't know how to set TargetType of style in order to point out the UserControl that is being developed.
Here is an example how it could look like:
<UserControl.Resources>
<Style TargetType="this">
</Style>
</UserControl.Resources>
You can do it like this:
<UserControl x:Class="YourProjectName.UserControl1"
xmlns:local="clr-namespace:YourProjectName"
<UserControl.Resources>
<Style TargetType="{x:Type local:UserControl1}">
<Setter Property="Background" Value="Green"></Setter>
</Style>
</UserControl.Resources>
</UserControl>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With