This project has moved. For the latest updates, please go here.
1
Vote

RegisterVisualState in BaseViewModel throws Exception

description

RegisterVisualState in Jounce.Core.ViewModel.BaseViewModel throws an exception when an ObservableCollection of ViewModels which is bound to a ListBox changes. The ViewModels are bound to their corresponding views by the JounceViewConverter.
The binding looks like this:
 
<ListBox ItemSource="{Binding MyItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding Converter={StaticResource ViewConverter}}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
 
When the collection changes an ArgumentException 'the element with that key already exists' is thrown.
I fixed it by checking the dictionary first:
 
public void RegisterVisualState(string view, Action<string,bool> action)
{
if(!_visualStates.ContainsKey(view))
_visualStates.Add(view, action);
if (GoToVisualState == null)
{
GoToVisualState = action;
}
}
 
Is this an issue or am I doing something wrong?
Best regards
Holger

comments