你如何绑定一个ListBox的的SelectedItem到另一个ListBox的的SelectedItem的财产?

编程入门 行业动态 更新时间:2024-10-20 05:48:19
本文介绍了你如何绑定一个ListBox的的SelectedItem到另一个ListBox的的SelectedItem的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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的财产?

本文发布于:2023-11-06 14:14:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563915.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   财产   ListBox   SelectedItem

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!