1. 例子:targetType设置好就能够直接使用 user control中定义的 dependency property
<UserControl x:Class="myUserControl" x:Name="thisControl">
<UserControl.Resource/>
<UserControl.Style>
<Style TargetType="{x:Type local:myUserControl}">
<Setter Property="Background" Value="yellow" />
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsExpanded" Value="True"/>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<SetterProperty="Background" Value="Blue"/>
</MultiTrigger>
</Style.Triggers>
</Style>
</UserControl.Style>
2. 对于user control内部的element,要使用user control的property,最好就用binding,如:
< ToggleButton IsChecked="{Binding ElementName=thisControl,Path=IsExpanded,Mode=TwoWay}" />
3. Style.Trigger 中的triiger不能使用SourceName,setter 不能用TargetName,这些只能在template中使用,因为template中才有可视树。在template中例子如下:
<DataTemplate.Triggers >
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
<Condition SourceName="MoreTextBlock" Property="Visibility" Value="Visible"/>
</MultiTrigger.Conditions>
<Setter TargetName="OneTextBox" Property="MaxLines" Value="200" />
<Setter TargetName="OneTextBlock" Property="Text" Value=""/>
</MultiTrigger>
</DataTemplate.Triggers>