我試圖建立一個HamburgerMenu這裏是菜單樣式:WPF觸發沒有認出控制來改變其屬性
<Style TargetType="local:HamburgerMenu">
<Style.Resources>
<!-- Fill Brushes -->
<SolidColorBrush x:Key="DarkBrush" Color="#40000000" />
</Style.Resources>
<Setter Property="Width" Value="50"/>
<Setter Property="Visibility" Value="Visible"/>
<Setter Property="IsOpen" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:HamburgerMenu">
<Grid x:Name="mainGrid" Background="{TemplateBinding Background}">
<ToggleButton x:Name="menuIcon" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="50" IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:HamburgerMenu}}, Path=IsOpen}">
<Path x:Name="path" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform" Width="30" Fill="{TemplateBinding MenuIconColor}" Data="M2,15.5L22,15.5 22,17.5 2,17.5 2,15.5z M2,10.5L22,10.5 22,12.5 2,12.5 2,10.5z M2,5.5L22,5.5 22,7.5 2,7.5 2,5.5z"/>
</ToggleButton>
<ListBox ItemsSource="{TemplateBinding Content}" HorizontalAlignment="Left" Margin="0,40,0,0" VerticalAlignment="Top" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectedIndex="0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsOpen" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="Width"
To="300"
Duration="0:0:0.3" AccelerationRatio="0.1" DecelerationRatio="0.9"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="Width"
To="50"
Duration="0:0:0.2"/>
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
現在我的問題是如何能夠在切換按鈕 觸發鼠標懸停此代碼不能正常工作監守TargetName =「路徑」不被識別! :
<ToggleButton.Triggers >
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="path" Property="Fill" Value="{StaticResource DarkBrush}" />
</Trigger>
</ToggleButton.Triggers>
,該溶液的作品,但不完全是因爲它觸發菜單的鼠標懸停不只是ToogleButton所以,當鼠標懸停在無處不在菜單的ToogleButton的顏色會發生變化:
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="path" Property="Fill" Value="{StaticResource DarkBrush}" />
</Trigger>
</ControlTemplate.Triggers>
你嘗試這樣或發生了什麼事? – mm8