开发者

How to display selected item / value in twoway binding combobox?

开发者 https://www.devze.com 2023-01-16 09:16 出处:网络
I have one combobox which have Mode twoway binding. I binded combobox to list of family members(MemberId,MemberType) table.

I have one combobox which have Mode twoway binding. I binded combobox to list of family members(MemberId,MemberType) table. I want to display selected Item (MemberType开发者_如何学Python) from list..


You can bind the SelectedItem property on the ComboBox to a property in your code-behind.

If you need to display this as a visual item, then you can do this by binding the Content of a ContentPresenter to that selected item.

As an example

<ComboBox ItemsSource={Binding Path=Collection} SelectedItem={Binding Path=MySelectedItem}/>
<ContentPresenter Content={Binding Path=MySelectedItem}/>

And in your code behind: (replacing "object" with whatever your colleciton is)

private object m_selectedItem;
public object MySelectedItem
{
    get { return m_selectedItem; }
    set
    {
        m_selectedItem = value;
        PropertyChanged(this, new PropertyChangedEventArgs("MySelectedItem"));
    }
}

You will have to implement the INotifyPropertyChanged interface in your code behind for this to work however


Bind SelectedItem to

public FamilyMember Selectedmember { get{...} set{...} }.....

and ensure that you call NotifyPropertyChanged methods in the setter for this member.

Then you can bind other objects on the view to this SelectedMember and display any information you may need.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号