Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding ListViewItem Background to boolean
    primarykey
    data
    text
    <p>Probably a simple one but i can't seem to get it to work, here's the XAML for the listview and bindings;</p> <pre><code>&lt;ListView VerticalAlignment="Stretch" HorizontalAlignment="Stretch" x:Name="lstTrackers" ItemsSource="{Binding Path=MainWindowViewModel.TrackerCollection}" HorizontalContentAlignment="Stretch"&gt; &lt;ListView.ItemContainerStyle&gt; &lt;Style TargetType="{x:Type ListViewItem}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding Path=LastTransmitted}" Value="True"&gt; &lt;Setter Property="Background" Value="Green"/&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding Path=LastTransmitted}" Value="False"&gt; &lt;Setter Property="Background" Value="White"/&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/ListView.ItemContainerStyle&gt; &lt;ListView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding Path=Description}" x:Name="listTextClick" MouseLeftButtonUp="listTextClick_MouseLeftButtonUp" HorizontalAlignment="Stretch"/&gt; &lt;/DataTemplate&gt; &lt;/ListView.ItemTemplate&gt; &lt;/ListView&gt; </code></pre> <p>and the property that i'm trying to bind it to;</p> <pre><code> public class TrackerViewModel : ViewModelBase { readonly Tracker _tracker; public TrackerViewModel(Tracker tracker) { _tracker = tracker; } public bool LastTransmitted { get { return _tracker.lastTransmitted; } set { _tracker.lastTransmitted = value; OnPropertyChanged("LastTransmitted"); } } } </code></pre> <p>And then i'm simply trying to set the boolean to true, which i assumed would trigger the style to proc;</p> <pre><code> _trackerViewModel.LastTransmitted = true; </code></pre> <p>However, nothing at all seems to happen. Is there something simple yet imperative that i'm missing?</p> <p>Note: I've already tried changing "true" to "True", just incase.</p> <p>Edit 1: It seems that the change isn't being notified, which is very strange because i'm certain it was. If i change the trigger to;</p> <pre><code>&lt;Style x:Key="listBoxStyle" TargetType="{x:Type TextBlock}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding Path=LastTransmitted}" Value="True"&gt; &lt;Setter Property="Background" Value="Green"/&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding Path=LastTransmitted}" Value="False"&gt; &lt;Setter Property="Background" Value="Blue" &gt;&lt;/Setter&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;!--&lt;Setter Property="Background" Value="Red"/&gt;--&gt; &lt;/Style&gt; </code></pre> <p>Then the textblocks are all blue, as denoted by the boolean being set to true. However When it is set to true, and the property is notified, nothing changes. Perhaps the list isn't refreshing properly? I'm sure it's linked to a ObservableCollection.</p> <p>EDIT 2: and on that note, it turns out i'm using a custom list; "ThreadedBindingList". It might not be updating from the OnNotify..so i'll have to try working around this.</p>
    singulars
    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