我无法根据布尔表达式设置TextBlock的值。
我的团队课程中有这个属性:
private Enums.YesOrNo yesOrNoOperator;
public Enums.YesOrNo YesOrNoOperator
{
get
{
return this.yesOrNoOperator;
}
set
{
this.yesOrNoOperator = value;
OnPropertyChanged("YesOrNoOperator");
}
}
private bool isYesOperator = false;
public bool IsYesOperator
{
get
{
return this.isYesOperator;
}
set
{
this.isYesOperator = value;
OnPropertyChanged("IsYesOperator");
}
}
因此默认设置为false。所以,理想情况下,如果此属性设置为true,我想显示“是”,否则显示“否”。
问题是,这个String配置将在另一个地方被引用,我无法有效地引发Property Changed事件。我使用ENUM来存储'YES'或'NO'值的值。
<TextBlock Style="{StaticResource TextBlockBaseStyling}" VerticalAlignment="Center" Text="{Binding YesOrNoOperator, UpdateSourceTrigger=PropertyChanged}"/>
<ToggleButton Style="{StaticResource ToggleViewSwitch}"
Visibility="{Binding IsToggleVisible, UpdateSourceTrigger=PropertyChanged}"
IsChecked="{Binding IsYesOperator, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
</Grid>
</Grid>
<ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="2" Grid.Column="1" Grid.Row="1"/>
</Grid>
</Border>
</Grid>
<TextBlock Style="{StaticResource TextBlockBaseStyling}"
Text="{Binding Parent.YesOrNoOperator, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding IsOperatorVisible, Converter={StaticResource BooleanConverter}, UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0, 10, 0, 0"/>
所以在这里,Parent.YesOrNoOperator和YesOrNoOperator在技术上都是相同的属性。
当您切换按钮时,我想要的是,这两个属性都设置为“是”或“否”。希望这是有道理的。