简体   繁体   中英

WPF DataBinding to property in control

I Have A wpf UserControl with a property:

private IEnumerable<PropertyBase> properties;
public IEnumerable<PropertyBase> Properties
{
    get {return properties;}
    set
    {
        properties = from property in value
             orderby property.Position
            select property;
    }
}

I want to create a ListBox that is bound to my Properties property with Property.Name as the displayed value, all the examples I'm finding use DataProviders in separate classes and appear to overcomplicate the situation. Is there a simpler way of achieving this.

I tried the following but no data was displayed:

<ListBox Name="propertiesListBox" ItemsSource="{Binding Source=this, Path=Properties}" DisplayMemberPath="Name" />
<ListBox ItemsSource="{Binding Properties}" DisplayMemberPath="Name"/>

假设您的DataContextUserControl实例。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM