[MVVM] Execute method when mui:Link is clicked

Apr 19, 2013 at 3:45 PM
i would like to execute a method defined in my ViewModel when i click on a mui:Link.

I tried to use the IContent which provides the OnNavigatedTo method.
        public void OnNavigatedTo(NavigationEventArgs e)
            MainViewModel vm = this.DataContext as MainViewModel;

            vm.DoSomething.Execute(new object());
It is working but i don't like this approach and looking for better ways to do so.

Would be cool to execute an RelayCommand on mui:link click.

Is there a better solution with less or cleaner Code Behind?

btw: great job, i LOVE m:ui!
Apr 20, 2013 at 12:04 PM
Where do you use a Link that needs to execute a ICommand? IMHO links in the main menu should always perform a page load. The title links however should be able to perform a ICommand execute. I'm working on a solution.
Apr 22, 2013 at 8:41 AM
i have a page where the content of the page depends on another page. The generation takes some time so i would like to do it only when it is necessary. Necessary in this context means only when the user actually wants to see the generated content. That is why it would be great to be able to perform an action on page load.

To be more specific: on page one i have a textbox containing xml code which should be transformed via XSLT when the user opens the second page which will display the result of the transformation.

I'm think about something like this:
        <mui:LinkGroup DisplayName="PROCESSING">
                <mui:Link DisplayName="XML" Source="/Pages/Xml.xaml" Command="{Binding GenerateCommand, Mode=OneWay}"/>
                <mui:Link DisplayName="Transformed XML" Source="/Pages/Result.xaml" />
Thanks for your effort!
Apr 23, 2013 at 10:04 PM
Not sure adding an explicit command to links is the solution. How about moving your xml and xslt translation logic to a viewmodel that is used in both your xml.xaml and result.xaml? When the result page is created, you should initate your transform logic in your view model.
Apr 24, 2013 at 7:53 AM
both pages already share the same view model instance. As far as i know the page is created only once (doesn't work to trigger the transformation in constructor or in the UserControl_Initialized event). Hence, the user cannot switch back, change something in the xml and trigger the transformation again.

The current OnNavigatedTo() approach doesn't trigger the content is loading indication progress bar.

However i would love to see the ability to hook in when a link is clicked. The proposed command thing is just one way todo it, but an simple link click event would also satisfy my needs. This is also one of the highest rated feature requests suggested by the community (see issuetracker)
Apr 24, 2013 at 7:31 PM
Adding link click events to the various controls is definitely going to happen soon. If that solves your issue as well, then consider that the solution.
Apr 25, 2013 at 7:34 AM
okay, thank you
Mar 5, 2014 at 11:51 AM
I'm using MUI framework. It's awesome.
For some reason, I'm looking forward to link click events too.
Is it available now?
Apr 14, 2014 at 6:00 AM
Edited Apr 14, 2014 at 6:00 AM
Any solution is available now?