我在UI的列表框绑定到List<Notification> Notifications { get; set; }
:如何将ListBox的SelectedItem绑定到另一个ListBox的SelectedItem的属性?
<ListBox ItemsSource="{Binding Notifications}"
DisplayMemberPath="ServiceAddress"
Name="NotificationsList"/>
通知已与其相关联的过滤器标题:
public class Notification
{
public string FilterTitle { get; set; }
public string ServiceAddress { get; set; }
}
我的UI具有绑定到List<LogFilter> Filters { get; set; }
另一个列表框:
<ListBox ItemsSource="{Binding Filters}"
DisplayMemberPath="Title"
Name="FiltersList"/>
正如你所猜,一个LogFilter包含一个标题:
public class LogFilter
{
public string Title { get; set; }
}
当我在我的NotificationsList中选择通知时,我希望它根据通知的FilterTitle和LogFilter的标题的映射在我的FiltersList中选择相应的LogFilter。你怎么能通过绑定来做到这一点?
但是现在,当您选择在第一个列表框中的通知,然后更改第二个列表框中的过滤器,它会取消选择您在第一个列表框中选择的通知,而这不是我之后的功能......我希望能够更改过滤器通知。那可能吗? – Alexandru
无法正确识别您,但我认为您只需要单向绑定,即选择了任何通知时,相应的标题被选中,而不是相反。如果是这种情况,您需要在绑定时设置“Mode = OneWay”。在答案中更新。 –
它仍然缺少一些东西,因为它似乎没有从第一个列表框中正确更新。所以,我在第一个列表框中有一个通知列表,当我选择一个时,更新第二个列表框。当我更改第二个列表框中的选择时,我希望它将第一个列表框中的FilterTitle数据项(选定通知的一部分)更改为我在第二个列表框中选择的过滤器。 PS,我感谢迄今为止的帮助! – Alexandru