0

我在silverlight4中的組合框的數據模板中有一個複選框。現在我想要在複選框的selectedindex改變它的事件。所以我怎麼能做到這一點?如何在silverlight4中的組合框的數據模板內獲取控件

這裏是我的代碼:

<ComboBox Height="Auto" x:Name="CB_Categories" SelectionChanged="CB_Categories_SelectionChanged" Tag=""> 
           <ComboBox.ItemTemplate> 
            <DataTemplate> 
            <CheckBox IsChecked="False" Content="{Binding Name}" CommandParameter="{Binding ProductCategoryID}" Click="CheckBox_Click" /> 
            </DataTemplate> 
           </ComboBox.ItemTemplate> 
          </ComboBox> 

請幫我傢伙。

感謝,

回答

1

雖然可以這樣做,你可能會被關閉,只是綁定要調查或改變,在後臺視圖模型或控制器的值複選框屬性越好。

E.g.如果這是您要更改爲true IsChecked,那就試試這個:

<ComboBox ItemsSource="{Binding Options}"> 
    <ComboBox.ItemTemplate> 
     <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" Content="{Binding Description}" /> 
    </ComboBox.ItemTemplate> 
</ComboBox> 

你也將:

<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" Content="{Binding Description}" /> 

然後,使用其ItemsSource財產掛鉤的ComboBox到項目列表必須設置容器控件的DataContextComboBox,以便控件可以訪問具有這些屬性的對象。

這樣做,意味着您可以在控制或窗口的代碼隱藏方面擁有更少的代碼,只需執行更新控件等管道工作即可。

如果您需要更多示例,請告訴我...

+0

感謝您的幫助Martin ...... –

相關問題