Question

I am developing a desktop application using Modern UI for WPF. I try to refresh my tab page when I go to a new tab page, but I couldn't.

I want to refresh my MUI WPF tab page when I go to another page using my tab controller.

Can anyone help me?

Was it helpful?

Solution 2

You can use SelectionChanged event to handle this. You can refresh MUI WPF tab page by using SelectionChanged.

<TabControl x:Name="MyTab" SelectionChanged="MyTabControl_SelectionChanged">
    <TabItem x:Name="TabItem1" Header="Tab 1"/>
    <TabItem x:Name="TabItem2" Header="Tab 2"/>
    <TabItem x:Name="TabItem3" Header="Tab 3"/>
</TabControl>

Then you can access to each TabItem at the event:

private void MyTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e){
    if (TabItem1.IsSelected){}
    if (TabItem2.IsSelected){}
    if (TabItem3.IsSelected){}  
}

OTHER TIPS

I'm not quite sure what you mean exactly, but by calling InvalidateVisual() on a control, you can force a visual refresh of it if that's what you're after, as it sounds like you've got a WPF control that isn't being updated when the data is changing.

Based on the MSDN documentation, this:

Invalidates the rendering of the element, and forces a complete new layout pass. OnRender is called after the layout cycle is completed.

For example:

        var grid = new Grid();
        // Our grid should refresh after this, 
        // although in normal circumstances it would by default regardless.
        grid.InvalidateVisual();    

I hope that this is of use.

While the selected answer is ok, it might not be the best way to go about it.

MUI includes a content navigation framework that handles content loading, unloading and history navigation based on link uris. If you want your content to be aware of navigation events such as loaded and unloaded events, you'll need to implement an interface.

Make your content navigation aware by implementing the IContent interface available in the FirstFloor.ModernUI.Windows namespace.

A simple Example is :

public class MyContent : UserControl, IContent
{
  public void OnFragmentNavigation(FragmentNavigationEventArgs e)
  {
  }
  public void OnNavigatedFrom(NavigationEventArgs e)
  {
  }
  public void OnNavigatedTo(NavigationEventArgs e)
  {
    //Refresh your page here
  }
  public void OnNavigatingFrom(NavigatingCancelEventArgs e)
  {
    // ask user if navigating away is ok
    if (ModernDialog.ShowMessage("Navigate away?", "navigate", MessageBoxButton.YesNo) == MessageBoxResult.No) {
      e.Cancel = true;
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top