如何将Visibility
元素的Grid
绑定到两个Checkbox
元素。如果至少检查其中一个网格,我希望显示网格。 我不想使用转换器。
这就是我所拥有的:
/// <summary>
/// Identifies whether the tags will be copied from source to target host
/// </summary>
private bool pasteTags = true;
public bool PasteTags
{
get { return pasteTags; }
set
{
pasteTags = value;
RaisePropertyChanged("PasteTags");
}
}
/// <summary>
/// Identifies whether the dimensions will be copied from source to target host
/// </summary>
private bool pasteDimensions = true;
public bool PasteDimensions
{
get { return pasteDimensions; }
set
{
pasteDimensions = value;
RaisePropertyChanged("PasteDimensions");
}
}
/// <summary>
/// Identifies if the views data grid is displayed or not.
/// </summary>
public System.Windows.Visibility IsViewGridVisible
{
get
{
if (pasteDimensions || pasteTags)
return System.Windows.Visibility.Visible;
return System.Windows.Visibility.Collapsed;
}
}
XAML:
<Grid Visibility="{Binding IsViewGridVisible}"> </Grid>
答案 0 :(得分:1)
您唯一需要的是在RaisePropertyChanged("IsViewGridVisible");
和PasteDimensions
两个属性集中调用PasteTags
。
public bool PasteDimensions
{
get { return pasteDimensions; }
set
{
pasteDimensions = value;
RaisePropertyChanged("PasteDimensions");
RaisePropertyChanged("IsViewGridVisible");
}
}
这是必需的,因为IsViewGridVisible
取决于这些属性的两个值,并且需要告知WPF有关更改(它无法以任何其他方式解决)。
答案 1 :(得分:1)
您实际上并不需要IsViewGridVisible
属性。
相反,您可以定义一个样式,在Visibility
和MultiDataTrigger
属性上按PasteTags
设置网格的PasteDimensions
:
<Grid>
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding PasteTags}" Value="True"/>
<Condition Binding="{Binding PasteDimensions}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Visible"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
</Grid>