2

私はをその子の 1 つとしてUserControl持っています。コントロールを使用するときにそれ自体に依存関係プロパティを定義し、子にこの値を独自のプロパティとして使用させListBoxたいと思います。 ItemsSourceUserControlListBoxItemsSource

のコードビハインドでタイプの依存関係プロパティを定義しましたIEnumerable( も使用してみましたObservableCollection)UserControlが、バインディングが適用されるのは 1 回だけのようです。ソース リストが変更されたときに、CollectionChanged通知がUserControlとその子ListBox

が に埋め込まれていないかのようにUserControlを更新するプロパティを定義するにはどうすればよいですか?ListBoxListBoxUserControl

これが私の 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>
4

0 に答える 0