在自定义UserControl

时间:2015-12-10 10:40:45

标签: c# wpf xaml data-binding win-universal-app

在Windows Universal应用中,我有一个自定义UserControl“ListControl”,其中包含ListView。我希望UserControl具有ItemsSource属性,以便我可以将ListView的{​​{1}}绑定到它。我尝试了以下方法,但获得了ItemsSource xaml异常:

Value does not fall within the expected range.

ListControl.xaml.cs

public static DependencyProperty MyItemsSourceProperty = DependencyProperty.Register("MyItemsSource", typeof(object), typeof(ListControl), new PropertyMetadata("")); public object MyItemsSource { get { return GetValue(MyItemsSourceProperty); } set { SetValue(MyItemsSourceProperty, value); } } ListControl.xaml)中:

x:Name="Control"

包含控件的页面:

<ListView ItemsSource="{Binding ElementName=Control, Path=MyItemsSource}">

绑定源:

<local:ListControl MyItemsSource="{Binding Instanz.ArtikelAlle, UpdateSourceTrigger=PropertyChanged}"/>

0 个答案:

没有答案