Monday, June 20, 2016

IsSynchronizedWithCurrentItem

I had an interesting problem today. Here's the scenario...

A user is in the search screen and the "Transaction Status" drop down list is set to "All".
The user performs a search, selects a transaction and goes to the edit screen.
The edit screen has a transaction status drop down list too, which is bound to the status of the selected transaction. Let's say the selected transaction has a status of "OPEN".
When the user returns to the search screen the Transaction Status drop down list now displays "OPEN" instead of "All".

Obviously the act of selecting "OPEN" in the edit page's drop down list is selecting "OPEN" in the search page's drop down list. This is commonly achieved by setting both drop down lists' IsSynchronizedWithCurrentItem="true" and sharing the same ItemsSource between both drop down lists.

Both drop down lists are bound to the same ItemsSource to improve performance. When I checked the default style for drop down lists I saw IsSynchronizedWithCurrentItem="true".

    <Style TargetType="{x:Type ComboBox}" x:Key="DropDownList" BasedOn="{StaticResource {x:Type ComboBox}}">
        <Setter Property="IsEditable" Value="False"/>
        <Setter Property="IsSynchronizedWithCurrentItem" Value="True"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
    </Style>

I have three possible solutions.

1. Bind each control to its own ItemsSource. This will slow the application down.
2. Change the default style. This may break something else.
3. Override the style with an explicit attribute.

<ComboBox Name="SearchGLDocumentStatusCombo" DisplayMemberPath="Description" SelectedValuePath="ID" Style="{StaticResource DropDownList}" IsSynchronizedWithCurrentItem="False"/>

No comments:

Post a Comment