-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HamburgerMenu Command MVVM #2848
Comments
@matej89 there are 2 options for you to set the selected content on the right side for the HamburgerMenu
<controls:HamburgerMenu x:Name="HamburgerMenuControl"
...
ItemClick="HamburgerMenuControl_OnItemClick"
OptionsItemClick="HamburgerMenuControl_OnItemClick"
...
DisplayMode="CompactInline">
</controls:HamburgerMenu> and private void HamburgerMenuControl_OnItemClick(object sender, ItemClickEventArgs e)
{
this.HamburgerMenuControl.Content = e.ClickedItem;
this.HamburgerMenuControl.IsPaneOpen = false;
}
<controls:HamburgerMenu x:Name="HamburgerMenuControl"
Foreground="White"
PaneBackground="#FF444444"
IsPaneOpen="False"
ItemTemplate="{StaticResource MenuItemTemplate}"
OptionsItemTemplate="{StaticResource OptionsMenuItemTemplate}"
DisplayMode="CompactInline">
<controls:HamburgerMenu.Content>
<MultiBinding Converter="{StaticResource SelectedItemToContentConverter}">
<Binding RelativeSource="{RelativeSource Self}"
Mode="OneWay"
Path="SelectedItem" />
<Binding RelativeSource="{RelativeSource Self}"
Mode="OneWay"
Path="SelectedOptionsItem" />
</MultiBinding>
</controls:HamburgerMenu.Content>
</controls:HamburgerMenu> and public class SelectedItemToContentConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
// first value is selected menu item, second value is selected option item
if (values != null && values.Length > 1)
{
return values[0] ?? values[1];
}
return null;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return targetTypes.Select(t => Binding.DoNothing).ToArray();
}
} You can find some more infos here |
Hi, thanks @punker76 . I understand this. But I don't know how to call method on viewmodel. In below I send you example how I want to do this hamburger menu. When click on item one I want to call method in viewmodel class. When click on item two I want call another method in viewmodel class. Regards, |
@matej89 You can use the loaded event of your views
|
@thoemmi can u give me simple example |
I mean instead of the normal events <controls:HamburgerMenu x:Name="HamburgerMenuControl"
...
ItemClick="HamburgerMenuControl_OnItemClick"
OptionsItemClick="HamburgerMenuControl_OnItemClick"
...
DisplayMode="CompactInline">
</controls:HamburgerMenu> adding bindable commands, like <controls:HamburgerMenu x:Name="HamburgerMenuControl"
...
ItemCommand="{Binding ItemClickedCommand}"
OptionsItemCommand="{Binding OptionsItemClickedCommand}"
...
DisplayMode="CompactInline">
</controls:HamburgerMenu> This would enable you to handle the commands in your viewmodel. |
@thoemmi but those Commands not shipped with HamburgerMenu |
@tomanye That was just a proposal, it's not implemented yet. |
@matej89 @tomanye another way without that we implement such commands is to use the interactivity stuff <controls:HamburgerMenu x:Name="HamburgerMenuControl"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
SelectedIndex="1"
Margin="20"
Foreground="White"
HamburgerWidth="48"
ItemTemplate="{StaticResource HamburgerMenuImageItem}"
OptionsItemTemplate="{StaticResource HamburgerMenuItem}"
PaneBackground="#FF444444">
<i:Interaction.Triggers>
<i:EventTrigger EventName="ItemClick">
<i:InvokeCommandAction Command="{Binding YourViewModel.YourItemClickCommand}"
CommandParameter="{Binding ElementName=HamburgerMenuControl, Path=SelectedItem}" />
</i:EventTrigger>
<i:EventTrigger EventName="OptionsItemClick">
<i:InvokeCommandAction Command="{Binding YourViewModel.YourOptionsItemClickCommand}"
CommandParameter="{Binding ElementName=HamburgerMenuControl, Path=SelectedOptionsItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</controls:HamburgerMenu /cc @thoemmi |
That should do the trick, as However, standard controls like |
@thoemmi thx, you're right, the commands could be useful (Command on MenuItem and ItemCommand and OptionsItemCommand on the HamburgerMenu itself). The tag property comes from the UWP toolkit code, I will add another property called |
@punker76 thanks , it Worked |
Hi, I am using alpha version and I tried the above mentioned idea to use event triggers but that does not seem to work. Any idea what I am doing wrong ? <metro:HamburgerMenu Thanks, |
Hi,
I didn't implemented command yet, but I will. In below I change the some
code, please check and let me know if working.
<metro:HamburgerMenu
x:Name="HamburgerMenuControl"
DisplayMode="CompactInline"
Foreground="White"
IsPaneOpen="False"
ItemTemplate="{StaticResource MenuItemTemplate}"
OptionsItemTemplate="{StaticResource OptionsMenuItemTemplate}"
PaneBackground="#FF444444">
<i:Interaction.Triggers>
<i:EventTrigger EventName="ItemClick">
<i:InvokeCommandAction Command="{Binding ItemCommand}"
CommandParameter="{Binding SelectedItem}" />
</i:EventTrigger>
<i:EventTrigger EventName="OptionsItemClick">
<i:InvokeCommandAction Command="{Binding OptionsItemCommand}"
CommandParameter="{Binding SelectedOptionsItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
Regards,
Matej
2017-03-21 19:00 GMT+01:00 smzuber <notifications@github.com>:
… Hi,
I am using alpha version and I tried the above mentioned idea to use event
triggers but that does not seem to work. Any idea what I am doing wrong ?
<metro:HamburgerMenu
x:Name="HamburgerMenuControl"
DisplayMode="CompactInline"
Foreground="White"
IsPaneOpen="False"
ItemTemplate="{StaticResource MenuItemTemplate}"
OptionsItemTemplate="{StaticResource OptionsMenuItemTemplate}"
PaneBackground="#FF444444">
<i:Interaction.Triggers>
<i:EventTrigger EventName="ItemClick">
<i:InvokeCommandAction Command="{Binding HamburgerMenu.ItemCommand}"
CommandParameter="{Binding ElementName=HamburgerMenuControl,
Path=SelectedItem}" />
</i:EventTrigger>
<i:EventTrigger EventName="OptionsItemClick">
<i:InvokeCommandAction Command="{Binding HamburgerMenu.
OptionsItemCommand}"
CommandParameter="{Binding ElementName=HamburgerMenuControl,
Path=SelectedOptionsItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
Thanks,
Zuber
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2848 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AYfk6qAhi0AfnHU2kcXEDNYrXrE2RoFZks5roBAkgaJpZM4L9Jrf>
.
|
That didnt't work either. I dont have access to code behind, so I have to do this in XAML only. Thanks |
Hi, I started using the hamburger menu and works nicely so far. But (warning - new to WPF) I have problems understanding the ItemCommandParamter for the menu. So my xaml looks like this right now: <Controls:HamburgerMenu x:Name="HamburgerMenuControl"
Foreground="#f3f3f7"
PaneBackground="#00437b"
IsPaneOpen="False"
ItemTemplate="{StaticResource MenuItemTemplate}"
OptionsItemTemplate="{StaticResource OptionsMenuItemTemplate}"
DisplayMode="CompactInline"
ItemCommand="{Binding SomethingSelected}"
ItemCommandParameter="{Binding ElementName=HamburgerMenuControl, Path=SelectedItem}"
ItemClick="HamburgerMenuControl_OnItemClick"
OptionsItemClick="HamburgerMenuControl_OnItemClick">
...
</Controls:HamburgerMenu> The normal button click events work fine of course. But I'd like to move that logic into the corresponding view models. It would be awesome if you could update one of your examples to show how to use the binding with viewmodels with ItemCommand and especially ItemCommandParamter. Thanks in advance |
Hi, I have a similar problem like @Gohico
This code work, but not, as expected, because DataTemplate HamburgerMenuItem is completely replaced. |
Not sure if this is of any help as I haven't touched this since... Last year...
Then in my UiBlabla.xaml.cs (so NOT the datamodel but the code behind the UI) I have the eventhandler
So the views are loaded based on the ' |
Hi,
I use hamburger menu and now I have the problem how to set viewModel to ItemsSource.
My item source are:
Thank you.
Regards,
Matej
The text was updated successfully, but these errors were encountered: