Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I change the property of an Element based on the property of an INotifyPropertyChanged object in an ObservableCollection?
    primarykey
    data
    text
    <p>I've got an <code>ObservableCollection&lt;User&gt;</code> full of User objects which implement <code>INotifyPropertyChanged</code>. The collection is set as the <code>DataContext</code> of my Window, which contains a <code>ListBox</code> (whose <code>ItemsSource</code> is also set to the same collection), a number of <code>TextBox</code>es, and a save <code>Button</code>, standard CRUD setup.</p> <p>I want to change the background of the save Button (and the background of the row in the ListBox which corresponds to the "current item") if one of the properties of the User objects changes. Should I be looking at styles and triggers?</p> <p>I have the following Style applied to my save Button, and the User objects have a <code>public bool IsDirty</code> property.</p> <pre><code>&lt;Style x:Key="PropertyChangedStyle" TargetType="Button"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding Source=???, Path=IsDirty}" Value="True"&gt; &lt;Setter Property="Background" Value="Red" /&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;Button ... Style="{StaticResource PropertyChangedStyle}"&gt; </code></pre> <p>I think I'm on the right track, but I don't understand how to point the binding to "the current item in an observable list which is set as the datacontext", where "current item" in this case is described by <code>CollectionViewSource.GetDefaultView(ListOfUsers).CurrentItem</code> (where <code>ListOfUsers</code> is my <code>ObservableCollection&lt;User&gt;</code>).</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.
    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