views:

82

answers:

2

Here's the situation:

Using WPF

I have an object set to the DataContext of a window. A listview on this window is bound to display a list of users which corresponds to a property in the DataContext(Users).

Whenever a A User is chosen I set the CurrentDisplayedUser to this user to the selected object.

I have another list box that's supposed to display Alerts by this user. This is accessible through User.Alerts.

My problem is that whenever I update the CurrentDisplayedUser property the list view that is bound to the CurrentDisplayedUser.Alerts is not updated.

Thanks in advance! I hope I have provided adequate information.

A: 

Did you use an ObservableCollection for your list of users?

jle
He doesn't mention if he's modifying the list of users - only that he's choosing a user from it. ObservableCollection won't help in that case.
Matt Hamilton
Thanks jle. I'm now updating my user collection to inherit from ObservableCollection. This is good when i get to the point that I'm adding functionality for adding users.
Joe
+1  A: 

Have you tried directly connecting the two lists using element binding rather than relying on an intermediary "CurrentDisplayedUser" property?

<Window ...>
    <StackPanel>
        <ListView x:Name="userList" ItemsSource="{Binding Users}">
           ...
        </ListView>

        <!-- display selected user here -->
        <ContentControl Content="{Binding SelectedItem,ElementName=userList />

        <ListView ItemsSource="{Binding SelectedItem.Alerts,ElementName=userList>
            ...
        </ListView>
    </StackPanel>
</Window>
Matt Hamilton
This works thanks! However, my intention was to have the Alerts list view change based on a double click event on the userList.
Joe
Might need to see some code then. Is your "CurrentSelectedUser" property a dependency property, or does your underlying object implement INotifyPropertyChanged?
Matt Hamilton