Created
November 25, 2015 16:44
-
-
Save voidtuxic/9fe514ab7eaf590ba1a8 to your computer and use it in GitHub Desktop.
MVVM, UWP and MenuFlyout binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- helper is the namespace with your converter --> | |
<helper:MenuItemToMenuFlyoutConverter x:Key="menuToFlyout"/> | |
<!-- button is simply binded to a MenuItem instance --> | |
<Button x:Name="menuItem" FlyoutBase.AttachedFlyout="{Binding Converter={StaticResource menuToFlyout}}" | |
Click="menuItem_Click" Content="{Binding Title}"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// code behind | |
private void menuItem_Click(object sender, RoutedEventArgs e) | |
{ | |
var btn = sender as Button; | |
var item = btn.DataContext as MenuItem; | |
if(item.HasChildren) | |
{ | |
FlyoutBase.ShowAttachedFlyout(btn); | |
} | |
else | |
{ | |
item.Command.Execute(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment