在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}"/>