且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Silverlight的列表框复选框所选项目

更新时间:2023-11-28 21:46:28

在SelectionChanged事件,你必须走可视树找到的复选框。您可以通过使用做到这一点VisualTreeHelper

In the selectionChanged event you have to "walk" the visual tree to find the checkbox. You can do this by using the VisualTreeHelper

这个例子表明你需要做的就是该复选框。

This example show what you need to do to get to the checkbox.

下面是一些其他的办法解决这一问题

您应该使用ListBoxItem中的复选框之间的RelativeSource绑定。 该datatemple包含一个复选框。将它更改为这样的。

You should use a RelativeSource binding between the ListboxItem and the CheckBox. The datatemple contains a checkbox. Change it to look like this.

<CheckBox 
  IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, 
    Path=IsSelected, Mode=TwoWay}" />

这将创建列表框的 IsSelected 的属性和CheckBox的器isChecked 的属性之间的绑定。 这个教程介绍了如何用一个例子。

This creates a binding between the IsSelected property of the ListBox and the IsChecked property of the CheckBox. This tutorial explains how with an example.

如果您需要更多的控制,你应该看一看的行为,并触发。他们是一个有点复杂,但给你更多的控制。

If you need more control, you should have a look at behaviors and triggers. They're a bit more complex but give you you more control.