代码之家  ›  专栏  ›  技术社区  ›  J4N

如何将WPF触发器中的同级元素作为目标?

  •  0
  • J4N  · 技术社区  · 7 年前

    我想有一个按钮,显示一个下拉菜单时,点击。

    到目前为止,我有:

        <dx:SimpleButton  Padding="1" Margin="1" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
                          Command="{Binding CreateItem}" >
            <DockPanel HorizontalAlignment="Stretch" LastChildFill="True">
                <Image DockPanel.Dock="Left" Width="16" Height="16" Source="../Resources/Add.png" Margin="10" />
                <dx:SimpleButton Name="DropDownButton" DockPanel.Dock="Right" Padding="1" Margin="0,1,1,1" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
                    <dx:SimpleButton.Content>
                        <Image Width="16" Height="16" Source="../Resources/customDropDown.png"  />
                    </dx:SimpleButton.Content>
                    <dx:SimpleButton.ContextMenu>
                        <ContextMenu x:Name="DropDownMenu" PlacementRectangle="{Binding RelativeSource={RelativeSource Self}}">
                            <MenuItem Command="{Binding PasteItem}" Header="Paste" />
                        </ContextMenu>
                    </dx:SimpleButton.ContextMenu>
                    <dx:SimpleButton.Triggers>
                        <EventTrigger SourceName="DropDownButton" RoutedEvent="Button.Click">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DropDownMenu" Storyboard.TargetProperty="(ContextMenu.IsOpen)">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <system:Boolean>True</system:Boolean>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </dx:SimpleButton.Triggers>
                </dx:SimpleButton>
                <TextBlock  VerticalAlignment="Center" Text="{Binding Path=Slot.Name}" /> 
            </DockPanel>
        </dx:SimpleButton>
    

    但当我点击按钮时,我发现了一个错误:

    'DropDownMenu' name cannot be found in the name scope of 'DevExpress.Xpf.Core.SimpleButton'.
    

    我错过了什么?

    0 回复  |  直到 7 年前