我在UI的列表框绑定到列表<通知和GT;通知{搞定;组; } :
I have a ListBox in my UI that is bound to List<Notification> Notifications { get; set; }:
<ListBox ItemsSource="{Binding Notifications}" DisplayMemberPath="ServiceAddress" Name="NotificationsList"/>的通知都有一个与之相关的过滤器标题:
A Notification has a filter title associated with it:
public class Notification { public string FilterTitle { get; set; } public string ServiceAddress { get; set; } }我的UI具有绑定到列表与另一个LT列表框; LogFilter&GT;过滤器{搞定;组; } :
<ListBox ItemsSource="{Binding Filters}" DisplayMemberPath="Title" Name="FiltersList"/>正如你可以猜到,一个LogFilter包含了一个标题:
And as you can guess, a LogFilter contains a Title:
public class LogFilter { public string Title { get; set; } }当我选择在我的NotificationsList通知时,我想它来选择根据通知的FilterTitle和LogFilter的标题的映射在我的FiltersList相应LogFilter。你怎么能做到这一点通过绑定?
When I select a Notification in my NotificationsList, I would like it to select the corresponding LogFilter in my FiltersList based on the mapping of the Notification's FilterTitle and the LogFilter's Title. How could you do that through a binding?
推荐答案所有你需要设置首先 SelectedValuePath 的第一个列表框 FilterTitle :
First of all you need to set SelectedValuePath for first listBox to FilterTitle:
<ListBox ItemsSource="{Binding Notifications}" DisplayMemberPath="ServiceAddress" Name="NotificationsList" SelectedValuePath="FilterTitle"/>绑定与的SelectedValue第一列表框使用的ElementName 。还需要设置 SelectedValuePath 到标题这里还有:
Bind with SelectedValue of first listbox using ElementName. Also you need to set SelectedValuePath to Title here as well:
<ListBox ItemsSource="{Binding Filters}" DisplayMemberPath="Title" Name="FiltersList" SelectedValuePath="Title" SelectedValue="{Binding SelectedValue, ElementName=NotificationsList, Mode=OneWay}"/>更多推荐
你如何绑定一个ListBox的的SelectedItem到另一个ListBox的的SelectedItem的财产?
发布评论