2016-09-27 17 views
2

Xceedの拡張WPFツールキットから借用しているWPFウィンドウにSplitButtonがあります。ドロップダウンの内容は、RadioButtonで構成されています。このような何かを生成WPF-クリック後にドロップダウンメニューを隠す方法

<Window x:Class="WpfTest.Test3" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:tk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit" 
     Title="Test3" Height="300" Width="300"> 
    <Grid Height="25" Width="150"> 
     <tk:SplitButton Content="Default Command"> 
      <tk:SplitButton.DropDownContent> 
       <StackPanel> 
        <RadioButton Content="Default Command" GroupName="variations" Margin="5" IsChecked="True"/> 
        <RadioButton Content="Alternate Command 1" GroupName="variations" Margin="5"/> 
        <RadioButton Content="Alternate Command 2" GroupName="variations" Margin="5"/> 
       </StackPanel> 
      </tk:SplitButton.DropDownContent> 
     </tk:SplitButton> 
    </Grid> 
</Window> 

:ような何か私はdissappearしないRadioButtonのドロップダウンメニューの各をクリックしたとき

test

問題は、あります。私はいくつかのグーグルを行い、それぞれRadioButtonClickイベントを処理する必要があることを認識しました。しかし、私はそのイベントハンドラのドロップダウンメニューを隠す方法を知らない。参考として、MenuItemhas the property ofStaysOpenOnClickと思われますが、他のコントロールにはそのようなものはありません。

プログラムでこれを行うだけでも十分ですが、これにはMVVMの方法がありますか?

+1

なく、あなたの問題の解決策が、なぜあなたは、ドロップダウンリスト上のラジオボタンを好むのですか? –

+0

@Zureドロップダウンリストは何ですか? 'SplitButton'は' DropDownContent'プロパティを持っています。これは 'MenuItem'sや何か試したようなもので埋められます。私はあなたが意味するものを得ていません –

+0

申し訳ありませんが、私はComboBoxを意味しています:https://www.dotnetperls.com/combobox-wpf –

答えて

1

ラジオボタンで[チェック済み]イベントを追加し、SplitoButton.IsOpen=false;を使用します。このコードに従ってください。

XAML

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:tk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <tk:SplitButton Name="SplitButton" Content="Default Command"> 

      <tk:SplitButton.DropDownContent> 

       <StackPanel> 
        <RadioButton Checked="rb_Checked" Content="Default Command" GroupName="variations" Margin="5" IsChecked="True"/> 
        <RadioButton Checked="rb_Checked" Content="Alternate Command 1" GroupName="variations" Margin="5"/> 
        <RadioButton Checked="rb_Checked" Content="Alternate Command 2" GroupName="variations" Margin="5"/> 
       </StackPanel> 

      </tk:SplitButton.DropDownContent> 
     </tk:SplitButton> 
    </Grid> 
</Window> 

正確には.cs

private void rb_Checked(object sender, RoutedEventArgs e) 
     { 
      SplitButton.IsOpen = false; 
     } 
関連する問題