Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't change selected list item style in wpf
    primarykey
    data
    text
    <p>I was trying to change list items appearance in dataTemplate but I had problem with changing a selected item look. I've found this question: <a href="https://stackoverflow.com/questions/146269/change-wpf-datatemplate-for-listbox-item-if-selected">Change WPF DataTemplate for ListBox item if selected</a></p> <p>and i tried to create similar code as in the answer:</p> <pre><code>&lt;DataTemplate x:Key="NoteTemplate"&gt; &lt;Border Margin="5" BorderThickness="1" BorderBrush="Transparent" Background="#F3EBC2" CornerRadius="4"&gt; &lt;Grid Margin="3" Width="395" MaxHeight="40"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition /&gt; &lt;RowDefinition/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid Row="0" &gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition/&gt; &lt;ColumnDefinition/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Grid.Column="0" FontSize="15" FontFamily="Consolas" FontWeight="Bold" Text="{Binding Path=tytul}"/&gt; &lt;TextBlock Grid.Column="1" FontSize="13" FontFamily="Consolas" FontStyle="Italic" HorizontalAlignment="Right" Text="{Binding Path=data_dodania}"/&gt; &lt;/Grid&gt; &lt;TextBlock Grid.Row="1" FontSize="13" FontFamily="Consolas" Text="{Binding Path=tresc}"/&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/DataTemplate&gt; &lt;Style TargetType="{x:Type ListBoxItem}" x:Key="ListBoxItem"&gt; &lt;Setter Property="ContentTemplate" Value="{StaticResource NoteTemplate}" /&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsSelected" Value="True"&gt; &lt;Setter Property="ContentTemplate" Value="{StaticResource NoteTemplate}" /&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>(I put the same template in trigger just to check if it works)</p> <pre><code>&lt;ListBox Name="listBoxNotatki" Margin="10" ItemContainerStyle="{StaticResource ListBoxItem}" Background="Beige" BorderBrush="Orange" BorderThickness="3"/&gt; </code></pre> <p>But then i got this error:</p> <p>"Unable to cast object of type 'MS.Internal.NamedObject' to type 'System.Windows.DataTemplate'."</p> <p>When I change StaticResource to DynamicResorce i get rid of this error but then the trigger in my style doesn't work (Selected item looks just like at the beginning). </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload