Вопрос

I have a checkbox inside the data template of combobox in silverlight4. Now i want to get the checkbox in combobox on selectedindex changed event of it.So how i can do that ?

Here is my code :

 <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>

Please Help me guys.

Thanks,

Это было полезно?

Решение

While it is possible to do so, you will probably be better off to just bind the checkbox property that you want to investigate or change, to a value in a background viewmodel or controller.

E.g. if it was the IsChecked that you want to change to true, then try this:

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

You then hook up the ComboBox to a list of items using its ItemsSource property:

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

Also you will have to set the DataContext of the container control or the ComboBox so that the control can access the object with those properties.

Doing it this way, means you can have less code in the code-behind of the control or window that is just doing plumbing work like updating controls.

If you need more examples, let me know...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top