首页 > 代码库 > WPF开发过程中遇到的小问题

WPF开发过程中遇到的小问题

1》在自定义控件时,如果想用到eventtrigger时,eventtrigger中的路由事件必须用该事件所在的类来修饰,否则访问不到该事件。例如:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<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>

  这里面如果直接写

?
1
RoutedEvent="Unchecked" 会把错,说找不到
?
1
Unchecked路由事件。