xml代码:
<ControlTemplate x:Key="ChkTemplate"
TargetType="ListViewItem">
<StackPanel Orientation="Horizontal">
<CheckBox Margin="0,0,3,0">
<CheckBox.IsChecked>
<Binding Path="IsSelected"
Mode="TwoWay">
<Binding.RelativeSource>
<RelativeSource Mode="TemplatedParent" />
</Binding.RelativeSource>
</Binding>
</CheckBox.IsChecked>
</CheckBox>
<ContentPresenter />
</StackPanel>
</ControlTemplate>
<DataTemplate DataType="{x:Type ABC:Info}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding}"
Margin="0,0,10,5" Foreground="Green"/>
<TextBlock Text="{Binding Channel}"
Margin="3,0,0,0"
Visibility="{Binding Path=Visible,ElementName=View, Converter={StaticResource BooleanConverter}}" />
<TextBlock.Foreground>
<SolidColorBrush Color="{Binding Foreground}" />
</TextBlock.Foreground>
</StackPanel>
</DataTemplate>
<Style TargetType="ListViewItem"
x:Key="SelectedItem">
<Setter Property="Template"
Value="{StaticResource ChkTemplate}" />
</Style>
班级:
public class Info : DependencyObject
{
public Brush Foreground
{
get { return (Brush)GetValue(ForegroundProperty); }
set { SetValue(ForegroundProperty, value); }
}
}
xml.cs:
private readonly RangeObservableCollection<Info> _validInfo;
Info.Foreground = Brushes.Red;
_validInfo.Add(Info);
上面的代码没有改变文本块的前景色我做错了什么?