两个ListBox之间的WPF单一选择 [英] WPF Single selection between two ListBoxes

查看:105
本文介绍了两个ListBox之间的WPF单一选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:我有两个的ListBox ,有两个不同的的ItemSource ,但两者的它们具有相同的结合的SelectedItem ,因为我想这两个列表之间进行单项选择。

I'm having the following problem: I have two ListBox, with two different ItemSource, but both of them have the same binding for the SelectedItem, because I was trying to perform a single selection between these two lists.

下面是一个形象,更好的显示问题:

Here's an image that better shows the problem:

我会想做什么?每次我从第一个列表中的一个项目(红色),它应该的选择的SelectedItem 从第二个列表(黑色)和反之亦然。这就是为什么我使用同样的结合对他们俩的。
我真的不知道这是否是更好的方式来做到这一点,但它应该工作那样。

What would I like to do? Every time I select one item from the first list (in red), it should deselect the SelectedItem from the second list (in black), and vice versa. That's why I'm using the same binding for both of them. I really don't know if it's the better way to do it, but it should work like that.

你能帮助我吗?

推荐答案

我不得不这样做是在第一遍的财产,并通知不断变化的,然后我通过实际价值的财产,并通知切换到视图。
像这样:

What I had to do was at first pass null to the property and notify the changing, and then I passed the real value to the property and notified the changing to the view. Like that:

protected Bar selectedItem;
public Bar SelectedItem{
    get
    {
        return selectedItem;
    }
    set
    {
        selectedItem = null;
        NotifyPropertyChanged("SelectedItem");

        selectedItem = value;
        NotifyPropertyChanged("SelectedItem");
    }



我得到这个答案,例如,从的this问题

这篇关于两个ListBox之间的WPF单一选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆