Value converter is not triggered within user control if used as list box item

To display a WPF list box, I use a user control (MessageRowTemplate) as list box item. The user contrul uses a value converter (MessageTypeToBrushConverter). For some reason, the value converter is only trigered if the user control isn't used as list box item but seperate.

xaml-file with user control used seperately and inside a list box as list box item:

<local:MuuriWindow x:Class="Muuri_UI_WPFv3.Window_Conversation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Muuri_UI_WPFv3" 
Loaded="EventHandler_WindowLoaded">
<Window.Resources>
    <DataTemplate x:Key="ResponsesListTemplate">
        <local:MessageRowTemplate Margin="3" />
    </DataTemplate>
    <local:MessageTypeToBrushConverter x:Key="converter" />
</Window.Resources>
<StackPanel Orientation="Vertical">
    <local:MessageRowTemplate x:Name="questionControl" />
    <ListBox HorizontalAlignment="Stretch" ItemTemplate="{DynamicResource ResponsesListTemplate}" ItemsSource="{Binding}"  Name="listBoxResponses" Height="200" ScrollViewer.VerticalScrollBarVisibility="Visible" Style="{StaticResource MuuriListboxStyle}" />
    <StackPanel Orientation="Horizontal">
        <Button Name="buttonReply" Click="EventHandler_ButtonReplyClicked">Reply</Button>
        <Button Name="buttonCancel" Click="EventHandler_ButtonCancelClicked">Cancel</Button>
    </StackPanel>
</StackPanel>
</local:MuuriWindow>

And here's the MessageRowTemplate.xaml:

<UserControl x:Class="Muuri_UI_WPFv3.MessageRowTemplate"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Muuri_UI_WPFv3" 
Width="300"
Loaded="UserControl_Loaded">
<UserControl.Resources>
    <local:MessageTypeToBrushConverter x:Key="converter" />
</UserControl.Resources>
<Grid Margin="2,1,2,1" VerticalAlignment="Top" Height="auto">
    <Grid.RowDefinitions>
        <RowDefinition Height="2" />
        <RowDefinition Height="0.5*" />
        <RowDefinition Height="0.5*" />
        <RowDefinition Height="2" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="15"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Border Name="leftBorder" Margin="2,2,0,2" Grid.RowSpan="4" CornerRadius="3,0,0,3" Panel.ZIndex="1" Background="{Binding Path=Type, Converter={StaticResource converter}}" />
    <Border Margin="0,0,0,0" Grid.Column="1" Grid.ColumnSpan="2" Grid.RowSpan="4" Background="#FF666666" CornerRadius="0,5,5,0" />
    <Border Margin="0,0,0,0" Grid.ColumnSpan="2" Grid.RowSpan="4" Background="{x:Null}" BorderThickness="2,2,2,2" BorderBrush="#FF202020" CornerRadius="5,5,5,5" Panel.ZIndex="0" />
    <TextBlock Padding="5,2,5,2" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Text="{Binding Path=Text}" Grid.Row="1" Grid.Column="1" Foreground="White" />
    <TextBlock Padding="5,2,5,2" HorizontalAlignment="Stretch" VerticalAlignment="Center" Text="{Binding Path=Author}" Grid.Row="2" Grid.Column="1" Foreground="White" />
</Grid>
</UserControl>

As you might guess, the value converter is responsible for converting some value to a brush. It works fine for this <local:MessageRowTemplate x:Name="questionControl" /> but not for the list box item.

Google didn't give me any hints for keyword combinations of 'list box', 'list box item', 'user control', 'value converter'.

Do you have an idea?

Thanks in advace.

Answers


The list box

<ListBox HorizontalAlignment="Stretch" ItemTemplate="{DynamicResource ResponsesListTemplate}" ItemsSource="{Binding}"  Name="listBoxResponses" Height="200" ScrollViewer.VerticalScrollBarVisibility="Visible" Style="{StaticResource MuuriListboxStyle}" />

uses the local resource ResponsesListTemplat which again uses the MessageRowTemplate. The converter is used within this template:

<UserControl.Resources>
    <local:MessageTypeToBrushConverter x:Key="converter" />
</UserControl.Resources>

and applied to the first border-tag within the template.


Need Your Help

Jinja2 block nesting issue

python flask jinja2

I am using jinja2 as a template language in my project. Here is simplified templates structure:

JSON from PHP to JavaScript

php javascript json

A slightly different question that all the others out there... I am able to easily pass JSON from a PHP page to JavaScript using the jQuery.ajax() method, but here is my situation:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.