1》在自定义控件时,如果想用到eventtrigger时,eventtrigger中的路由事件必须用该事件所在的类来修饰,否则访问不到该事件。例如:
<ToggleButton x:Name="PART_toggleButton" VerticalAlignment="Top" IsChecked="False" Style="{StaticResource ToggleButtonStyle}" HorizontalAlignment="Center"> <ToggleButton.Triggers> <EventTrigger RoutedEvent="ToggleButton.Checked" SourceName="PART_toggleButton"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_Listbox" Storyboard.TargetProperty="Height" Duration="0:0:1" To="100" FillBehavior="HoldEnd"/> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="ToggleButton.Unchecked" SourceName="PART_toggleButton"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_Listbox" Storyboard.TargetProperty="Height" Duration="0:0:1" To="0" FillBehavior="HoldEnd"/> </Storyboard> </BeginStoryboard> </EventTrigger> </ToggleButton.Triggers> </ToggleButton>
这里面如果直接写
RoutedEvent="Unchecked" 会把错,说找不到
Unchecked路由事件。