2017-02-10 90 views
0

我正嘗試用標題/標題創建一個簡單的dropdownlist/combobox。我重複簡單。我在Extended WPF Toolkit here中發現了這個漂亮的DropdownButton。問題是..它不包含任何像ItemsSourceDataSource,所以我甚至不能綁定我的集合=我不能使用MVVM模式(這在WPF中沒有意義)。我在這裏錯過了什麼嗎?如何將集合綁定到擴展WPF工具包的DropdownButton?

這裏是我的「目標」使用ComboBox

  <ComboBox Margin="5" ItemsSource="{Binding MyOptions}"> 
       <ComboBox.ItemTemplate> 
        <DataTemplate> 
         <CheckBox Content="{Binding DisplayName}" IsChecked="{Binding IsChecked, Mode=TwoWay}" /> 
        </DataTemplate> 
       </ComboBox.ItemTemplate> 
      </ComboBox> 

這個例子的例子幾乎是完美的,但我不能用簡單的Header="Check your options:"指定組合框的標題。

問題是:如何將ViewModel的集合綁定到DropdownButton控件?

感謝,

+0

我認爲目標是你把菜單(或whatevs)在DropDownContent及其綁定的ItemsSource到您的列表。您可以將Command綁定到每個指向您的ViewModel的ViewModel,它將當前項目作爲其CommandParameter。當用戶點擊時,請做你需要做的事情。 – Will

+1

您發佈的鏈接告訴我們您可以在其中放置任何自定義content_。 – jsanalytics

回答

1

的解決辦法是:

  <wpfTool:DropDownButton Content="Options"> 
       <wpfTool:DropDownButton.DropDownContent> 
        <ListView Margin="0" ItemsSource="{Binding MyOptions}"> 
         <ListView.ItemTemplate> 
          <DataTemplate> 
           <CheckBox Content="{Binding DisplayName}" IsChecked="{Binding IsChecked, Mode=TwoWay}" /> 
          </DataTemplate> 
         </ListView.ItemTemplate> 
        </ListView> 
       </wpfTool:DropDownButton.DropDownContent> 
      </wpfTool:DropDownButton> 
+0

完美!謝謝! –