您可以在 UserControl 中创建 DependancyProperty,例如
public static readonly DependencyProperty RadioButtonVisibilityProperty=
DependencyProperty.Register( "RadioButtonVisibility", typeof(Visibility),
typeof(MyUserControl));
public Visibility RadioButtonVisibility
{
get { return (Visibility)GetValue(RadioButtonVisibilityProperty); }
set { SetValue(RadioButtonVisibilityProperty, value); }
}
并在您的 UserControl 的 xaml 中设置单选按钮的可见性,例如
<RadioButton Visibility="{Binding Parent.RadioButtonVisibility,ElementName=LayoutRoot}"/>
并在您的主视图(创建/编辑)中这样做
<MyUserControl x:Name="Edit" RadioButtonVisibility="Visible"/>
或者
<MyUserControl x:Name="Create" RadioButtonVisibility="Hidden"/>
并且不要忘记给您的 UserControl 的父 Grid 命名为“LayoutRoot”
喜欢
<Grid x:Name="LayoutRoot"/>