0

He everybody!
What I want to do is to open a flyout with list of items (binded to a collection from a ViewModel) and then, when a user chooses any item in the list, the flyout should be hidden. To achieve this I'm using a behavior which hides the flyout. The problem is that the behavior doesn't work when I'm tapping on the item that is already chosen (on currently selected item).

I have the following code.

        <Button.Flyout>
            <Flyout Placement="Full">
                <interactivity:Interaction.Behaviors>
                    <core:DataTriggerBehavior Binding="{Binding SelectedCategory}"
                                              ComparisonCondition="NotEqual">
                        <controls:CloseFlyoutAction />
                    </core:DataTriggerBehavior>
                </interactivity:Interaction.Behaviors>
                <ListView ItemsSource="{Binding Source={StaticResource GroupedCategories}}"
                          SelectedItem="{Binding SelectedCategory, Mode=TwoWay}">
                    <ListView.GroupStyle>
                        <GroupStyle>
                           //... skiped for brevity
                        </GroupStyle>
                    </ListView.GroupStyle>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ContentControl Foreground="{Binding IsSelected, Converter={StaticResource ForegroundConverter}}"
                                            Content="{Binding Name}" />
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Flyout>
        </Button.Flyout>
pasul
  • 1,182
  • 2
  • 12
  • 20
  • Probably because the ComparisonCondition is set to NotEqual, and selecting the already selected category means that those two are equal. Right? – Igor Ralic Sep 02 '14 at 11:30
  • I thought about it. Probably that's the reason. – pasul Sep 02 '14 at 12:15
  • 1
    I've come up to the solution with naming flyout, creating the Tapped event handler in code behind and hiding the flyout there...but that's not an ideal solution according to MVVM. – pasul Sep 02 '14 at 12:15
  • Well, instead of using the Tapped event handler, you could use the EventToCommandBehavior and have the code for the command in your VM, which would make Mr. MVVM very pleased :-) – Igor Ralic Sep 02 '14 at 14:33
  • MVVM is for managing data and binding, there's nothing wrong in adding an event handler for manipulating the UI :) – mcont Nov 02 '14 at 13:47

0 Answers0