我正在使用以下樣式集創建自定義wpf控件。在後面的代碼中,我有一個名爲selected的依賴屬性。當OnMouseLeftButtonDown觸發器被執行時,如何將此屬性設置爲true?如何從樣式觸發器設置依賴屬性
<Style TargetType="{x:Type local:myControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:myControl}">
<ControlTemplate.Resources>
<Storyboard x:Key="OnMouseLeftButtonDown">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" Storyboard.TargetName="border">
<EasingColorKeyFrame KeyTime="0" Value="#FF9B1111"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="UIElement.MouseLeftButtonDown" SourceName="textBlock">
<BeginStoryboard Storyboard="{StaticResource OnMouseLeftButtonDown}"/>
</EventTrigger>
<EventTrigger RoutedEvent="UIElement.MouseLeftButtonDown" SourceName="textBlock2">
<BeginStoryboard Storyboard="{StaticResource OnMouseLeftButtonDown}"/>
</EventTrigger>
</ControlTemplate.Triggers>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Border Name="border" BorderBrush="#FFDEDEDE" BorderThickness="1" Margin="1" >
<StackPanel Orientation="Horizontal">
<TextBlock Name="textBlock" HorizontalAlignment="Left" Margin="2,1,2,3" Text="{TemplateBinding ElementName}" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF7C8CF1" FontSize="10" FontWeight="Bold"></TextBlock>
<TextBlock Name="textBlock2" HorizontalAlignment="Left" Margin="2,1,2,3" Text="{TemplateBinding ElementText}" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF75757A" FontSize="10" FontWeight="Bold"></TextBlock>
</StackPanel>
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
公共靜態只讀的DependencyProperty SelectedProperty = DependencyProperty.Register(「Selected」,typeof(bool),typeof(XliffElement),new PropertyMetadata(default(bool))); public bool已選擇 { get {return(bool)GetValue(SelectedProperty); } set {SetValue(SelectedProperty,value); } } – John