Closed jfquarto closed 5 years ago
Do you need more information ?
If I use this instead of Command:
button.Click += Button_Click;
it works for every item I navigate to.
But I want to use Command because of MVVM.
@jfquarto Which MahApps version are you using?
@jfquarto I think this is fixed in the current dev branch b83db30511fed40eda672c0e302abc8f92348d39
Build MahApps from the current dev branch and used it in my project. But it didn't solve my problem.
@jfquarto It would be nice if you can create a short sample and separate this.
Here's the sample; FlipViewTest.zip
@jfquarto The problem here is, that you are mixing MVVm with creating visuals in code behind. It works for the first tab, because there is a existing visual tree and for the other tabs it doesn't exists. In your case you can do this at the KeyboardCreator:
...
//
//the command binding
//
button.CommandParameter = id.ToString();
grid2.Children.Add(button);
grid2.Loaded += (sender, args) =>
{
BindingOperations.ClearBinding(button,Button.CommandProperty);
button.SetBinding(Button.CommandProperty, new Binding("DataContext.KeyCommand") {RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FlipView), 1)});
};
...
Thanx !
Met vriendelijke groet, Johan Fontijne Software developer
Quarto B.V. Westbaan 200 Moordrecht 2841 MC Nederland Tel: +31 182 700 500 Email: johan.fontijne@quarto.nl Web: www.quarto.nl De disclaimer van toepassing op e mail van Quarto Betaalsystemen vindt u op https://www.quarto.nl/disclaimer-quarto Van: Jan Karger notifications@github.com Verzonden: Friday, 14 December 2018 17:04 Aan: MahApps/MahApps.Metro MahApps.Metro@noreply.github.com CC: Johan Fontijne johan.fontijne@quarto.nl; Mention mention@noreply.github.com Onderwerp: Re: [MahApps/MahApps.Metro] Command binding not working on FlipView next item (#3375)
@jfquartohttps://github.com/jfquarto The problem here is, that you are mixing MVVm with creating visuals in code behind. It works for the first tab, because there is a existing visual tree and for the other tabs it doesn't exists. In your case you can do this at the KeyboardCreator:
...
//
//the command binding
//
button.CommandParameter = id.ToString();
grid2.Children.Add(button);
grid2.Loaded += (sender, args) =>
{
BindingOperations.ClearBinding(button,Button.CommandProperty);
button.SetBinding(Button.CommandProperty, new Binding("DataContext.KeyCommand") {RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FlipView), 1)});
};
...
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/MahApps/MahApps.Metro/issues/3375#issuecomment-447369586, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWHPuEk1k8-Cq2XmgBxsK9ZUckGFqdApks5u48wHgaJpZM4YtTz6.
My FlipView in Xaml:
MyTabs is an ObservableCollection of class Tab. Class Tab has a property Buttons which is a Grid with Button controls on it. Each button has a Command binding (MyTabs is created in the viewmodel constructor):
Now all works fine on the first FlipView item selected via SelectedIndex. If I click on a button the Command is executed. But when I navigate to next item the command binding of the buttons on that item don't work. Same goes for the next items. Only the buttons on the initial selected item will work ok. For example if I change the value of SelectedIndex in the Xaml to 2, then only the buttons on item 2 work ok.