2

DataGridCell 内に動的メニューを含むポップアップを使用すると問題が発生します。ポップアップを問題なく表示し、ウィンドウ内の他の場所をクリックしてフォーカスが失われると消えるようにすることができます。しかし、MenuItems の 1 つが選択されているときにポップアップを非表示にすることはできません。

私の CellTemplate の XAML は次のとおりです。

<DockPanel>
    <ToggleButton Content=" + "
                  FontWeight="Bold"
                  FontFamily="Arial"
                  Foreground="Green"
                  BorderBrush="Transparent"
                  IsThreeState="False"
                  DockPanel.Dock="Right"
                  Name="Button_AddDefinition">
    </ToggleButton>
    <Popup IsOpen="{Binding ElementName=Button_AddDefinition, Path=IsChecked}"
           StaysOpen="False"
           Placement="Right"
           PlacementTarget="{Binding ElementName=Button_AddDefinition}"
           AllowsTransparency="True">
        <Border CornerRadius="3"
                Background="WhiteSmoke"
                BorderBrush="DarkGray"
                BorderThickness="1">
            <Menu ItemsSource="{Binding Path=NewDefinitionTypes}">
                <Menu.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Orientation="Vertical" />
                    </ItemsPanelTemplate>
                </Menu.ItemsPanel>
                <Menu.ItemTemplate>
                    <DataTemplate >
                        <MenuItem Header="{Binding StringFormat='New {0}'}"
                                    Command="{Binding RelativeSource={RelativeSource AncestorType=Popup}, Path=DataContext.NewDefinitionCommand}"
                                    CommandParameter="{Binding}">
                        </MenuItem>
                    </DataTemplate>
                </Menu.ItemTemplate>
            </Menu>
        </Border>
    </Popup>
    <ComboBox SelectedItem="{Binding Path=Definition, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
                ItemsSource="{Binding Path=AvailableDefinitions}"
                BorderBrush="Transparent"
                MouseUp="DataGridCell_ComboBox_MouseUp"
                DisplayMemberPath="Name"
                Style="{StaticResource ValidationErrorStyle}">
    </ComboBox>
</DockPanel>

トグル ボタン (つまり、「+」) をクリックすると、ポップアップが表示され、項目ごとにメニュー項目が動的に取り込まれます。これは次のようになります。

ここに画像の説明を入力

ポップアップ以外の場所をクリックすると、ポップアップが消えます(私が望むもの)。しかし、アイテムの1つをクリックすると、ポップアップで選択を処理したいので、ポップアップは消えるはずです。それが私がここで探しているものです。ポップアップ内のアイテムが選択されると、ポップアップを非表示にするにはどうすればよいですか。私は MVVM プラットフォームで作業しているため、最小限のコード ビハインドが推奨されますが、ドグマは推奨されません。

何か案は?

4

0 に答える 0