WPF Usercontrol - Change resource property behind a IValueConverter class in the App

  • Thread starter Thread starter xderax
  • Start date Start date
X

xderax

Guest
Hi,

I have an usercontrol with a listview for logging. The log messages are shown in white and red(errors).
Now I want to configure the two colors from the control in the application.
The change of the background of the listview works with a DependencyProperty, but I cant figure out, how to change there the "NormalBrush" and "ErrorBrush".

...
<UserControl.Resources>
<local:LogTypeStyleConverter x:Key="LogTypeStyleConverter" NormalBrush="#FFB4B4B4" ErrorBrush="Red"/>
...

<ListView x:Name="lbLog" ItemsSource="{ Binding LogMessages}" FontFamily="Lucida Console" FontSize="10" Background="#FF2D2D30" Foreground="#FFB4B4B4">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Control.HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Control.VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Foreground" Value="{Binding Type, Converter={StaticResource LogTypeStyleConverter}}" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="true" >
<Setter Property="Background" Value="Transparent" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
...



public enum LOGTYPE
{
Error,
Trace
}

public class LogTypeStyleConverter : IValueConverter
{
public Brush NormalBrush { get; set; }
public Brush ErrorBrush { get; set; }

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return NormalBrush;
var type = (LOGTYPE)value;
if (type == LOGTYPE.Error)
return ErrorBrush;
else
return NormalBrush;

}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}

Continue reading...
 
Back
Top