私はをその子の 1 つとしてUserControl
持っています。コントロールを使用するときにそれ自体に依存関係プロパティを定義し、子にこの値を独自のプロパティとして使用させListBox
たいと思います。 ItemsSource
UserControl
ListBox
ItemsSource
のコードビハインドでタイプの依存関係プロパティを定義しましたIEnumerable
( も使用してみましたObservableCollection
)UserControl
が、バインディングが適用されるのは 1 回だけのようです。ソース リストが変更されたときに、CollectionChanged
通知がUserControl
とその子ListBox
。
が に埋め込まれていないかのようにUserControl
を更新するプロパティを定義するにはどうすればよいですか?ListBox
ListBox
UserControl
これが私の UserControl の簡略図です。
ItemsSource
プロパティの定義:
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(SidePanelItem), new FrameworkPropertyMetadata(null));
public IEnumerable ItemsSource
{
get { return (IEnumerable)GetValue(ItemsSourceProperty); }
set { base.SetValue(ItemsSourceProperty, value); }
}
このプロパティを として使用しようとしていListBox
ますItemSource
:
<UserControl x:Name="myControl">
<.. other elements ..>
<ListBox ItemsSource="{Binding ElementName=myControl, Path=ItemsSource}"/>
</.. other elements ..>
</UserControl>