TreeView item foreground binding MVVM
I am using TreeView to display my data. I want to bind foreground of a
tree view item. Here is my code below.
View:
<UserControl.Resources>
<HierarchicalDataTemplate x:Key="TreeViewItem" ItemsSource="{Binding
Children}">
<StackPanel Orientation="Horizontal">
<CheckBox Margin="2" IsChecked="{Binding IsChecked,
Mode=TwoWay}" Content="{Binding Title}"
Background="{Binding Path=ForegroundColor}"
IsThreeState="True"/>
</StackPanel>
</HierarchicalDataTemplate>
</UserControl.Resources>
<Grid>
<TreeView Margin="5, 0, 5, 0" ItemsSource="{Binding
GeoGraphixModules}" ItemTemplate="{StaticResource TreeViewItem}"
IsEnabled="{Binding TreeViewEnabled}" />
</Grid>
And in my view model
public class SomeTreeViewItem { public Collection Children { get { return
_children; } }
public Brush ForegroundColor
{
get
{
if (SomeCheck)
return Brushes.Green;
else
return Brushes.Red;
}
}
}
Now when I debug this application 'ForegroundColor' is hit but the
application still displays black as foreground for all the child items.
What is the problem here?
No comments:
Post a Comment