我的 xml 看起来像这样:
<UserControl>
<Grid>
...
<Grid>
...
<Grid Grid.Row="3">
<local:UserControl1 Visibility = "{Binding UserControl1Visibility}" />
<local:UserControl2 Visibility = "{Binding UserControl2Visibility}" />
</Grid>
</UserControl>
Control1Visibility 和 Control2Visibility 是我的 ViewModel 中的属性,但它不起作用。此网格无法动态显示两个用户控件。有人有想法吗?
编辑
虚拟机:
private Visibility userControl1Visibility = Visibility.Visible;
public Visibility UserControl1Visibility
{
get { return userControl1Visibility; }
set
{
if (userControl1Visibility != value)
{
userControl1Visibility = value;
RaisePropertyChanged("UserControl1Visibility");
}
}
}
private Visibility userControl2Visibility = Visibility.Collapsed;
public Visibility UserControl2Visibility
{
get { return userControl2Visibility ; }
set
{
if (userControl2Visibility != value)
{
userControl2Visibility = value;
RaisePropertyChanged("UserControl2Visibility");
}
}
}