我有一个有一些值的ListView。我想改变ListView的字体颜色,但是这段代码不起作用:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Title="Navi" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="603" Width="1029"
ShowInTaskbar="True" Closing="Window_Closing" Background="#FFD6D6D6">
<Window.Resources>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding DarkTheme}" Value="True">
<Setter Property="Control.Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>政务司司长:
public Int32 DarkTheme {get; set;}
//First init
public MainWindow()
{
DarkTheme = 1;
//Init component我做错了什么?
发布于 2012-12-31 01:37:48
将DarkTheme从Int32更改为bool。
public bool DarkTheme {get; set;}
DarkTheme = true;或
您还可以创建可在Binding中使用的Converter。
public class IntToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is int)
{
if ((int)value) == 1)
return true;
return false;
}
return DependencyProperty.UnsetValue;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool)
{
if ((bool)value) )
return 1;
return 0;
}
return DependencyProperty.UnsetValue;
}https://stackoverflow.com/questions/14092929
复制相似问题