前提
DataGridのMouseDoubleClickイベントにセルをWクリックした時に、トグルボタンのIsCheckedプロパティをTrueにし、トグルボタンにバインドされているポップアップを表示する処理を仕込んでいます。
問題・実現したいこと
以下のGifはセルをWクリックした時の動作です。
(3回Wクリックしています)
セルをWクリック時にポップアップが表示されすぐに消えてしまいます。
これを表示されたままにしたいのですが、上記の原因がわかりません。
何か解決方法はありますでしょうか?
コード
XAML
1<!--トグルボタン--> 2<ToggleButton Grid.Row="1" x:Name="ToggleButtonRegistedInfo" Margin="0" IsChecked="{Binding IsOpen, ElementName=PopupRegistedInfo}"> 3 <ToggleButton.Style> 4 <Style TargetType="ToggleButton" BasedOn="{StaticResource NormalToggleButtonStyle}"> 5 <Style.Triggers> 6 <DataTrigger Binding="{Binding IsOpen, ElementName=PopupRegistedInfo}" Value="True"> 7 <Setter Property="IsHitTestVisible" Value="False"/> 8 </DataTrigger> 9 </Style.Triggers> 10 </Style> 11 </ToggleButton.Style> 12 <Image Source="./Icons/assignment_white_192x192.png"/> 13</ToggleButton> 14 15<!--トグルボタンにバインドされているポップアップ--> 16<Popup x:Name="PopupRegistedInfo" PlacementTarget="{Binding ElementName=RegistedInfoToggleButton}" Style="{StaticResource MenuPopupStyle}"> 17 <Border Style="{StaticResource PopupPanelBorderStyle}"> 18 <ScrollViewer Margin="5" VerticalScrollBarVisibility="Hidden"> 19 <StackPanel x:Name="StackPanelRegistedInfo"> 20 <Label Content="R E G I S T E D I N F O" FontSize="20"/> 21 <Border Margin="0,5,0,5" Style="{StaticResource BottomSeparateBorderStyle}"/> 22 <Grid Margin="0"> 23 <Grid.ColumnDefinitions> 24 <ColumnDefinition/> 25 <ColumnDefinition/> 26 <ColumnDefinition/> 27 </Grid.ColumnDefinitions> 28 <Button Grid.Column="0" 29 x:Name="ButtonDeleted" 30 Content="削除" FontWeight="DemiBold" Margin="5,0,5,0" Width="Auto" Visibility="Collapsed" 31 Background="{Binding Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}}" 32 Click="ButtonDeleted_Click"/> 33 <Button Grid.Column="1" 34 x:Name="ButtonUpdated" 35 Content="更新" FontWeight="DemiBold" Margin="5,0,5,0" Width="Auto" Visibility="Collapsed" 36 Background="{Binding Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}}" 37 Click="ButtonUpdated_Click"/> 38 <Button Grid.Column="2" 39 x:Name="ButtonRegisted" 40 Content="登録" FontWeight="DemiBold" Margin="5,0,5,0" Width="Auto" Visibility="Collapsed" 41 Background="{Binding Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}}" 42 Click="ButtonRegisted_Click"/> 43 </Grid> 44 <Border Margin="0,5,0,5" Style="{StaticResource BottomSeparateBorderStyle}"/> 45 </StackPanel> 46 </ScrollViewer> 47 </Border> 48</Popup>
C#
1// データグリッドのマウスWクリックイベント 2private void View_MouseDoubleClick(object sender, MouseButtonEventArgs e) 3{ 4 if (!(sender is DataGrid dataGrid)) 5 return; 6 7 if (dataGrid.SelectedCells.Count == 0 || dataGrid.SelectedCells[0].Column.DisplayIndex != 0) 8 return; 9 10 // Popupにあるテキストボックスなどに値を入れる処理 11 SelectedItems = (string[])dataGrid.SelectedCells[0].Item; 12 for (int i = 0; i < SelectedItems.Length; i++) 13 { 14 var element = StackPanelRegistedInfo.Children[ControlIndexes[i]]; 15 if (element is TextBox textBox) 16 { 17 textBox.Text = SelectedItems[i]; 18 } 19 else if (element is ComboBox comboBox) 20 { 21 comboBox.Text = SelectedItems[i]; 22 } 23 } 24 ButtonUpdated.Visibility = Visibility.Visible; 25 ButtonDeleted.Visibility = Visibility.Visible; 26 27 // ToggleButtonとバインドしているPopupを表示 28 ToggleButtonRegistedInfo.IsChecked = true; 29}
試したこと

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。