あなたの子供のを管理するShowChildItemsプロパティをあなたに持たせるには、最初にそれを にする必要があります:UserControlVisibilityGridViewDependencyProperty
public static readonly DependencyProperty ShowChildItemsProperty =
DependencyProperty.Register("showChildItems", typeof (bool), typeof (MyUserControl), new PropertyMetadata(true));
public bool ShowChildItems
{
get { return (bool) GetValue(ShowChildItemsProperty); }
set { SetValue(ShowChildItemsProperty, value); }
}
の内部では、次の構文を使用して をこのプロパティにUserControlバインドします。この方法では、 が何にバインドされているかは問題ではありません。GridView VisibilityElementNameGridView DataContext
<GridView Visibility="{Binding ShowChildItems, ElementName=ControlRoot, Converter={StaticResource VisibilityConverter}}" ItemsSource="{Binding ChildItems}">
これを機能させるには、名前を のルート ノードに設定する必要がありUserControlます (残りの属性は省略しました)。
<UserControl
x:Name="ControlRoot">
また、コンバーターを使用してboolプロパティをバインドしましたVisibility:
<UserControl.Resources>
<local:BoolToVisibilityConverter x:Key="VisibilityConverter" />
</UserControl.Resources>
これはそのコードです:
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (!(value is bool)) return Visibility.Collapsed;
return (bool) value ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
これがあなたが求めていたものであることを願っています。あなたの質問に基づいて、私はよくわかりません。