简体   繁体   English

更改选项卡时刷新/重新加载MUI WPF页面

[英]Refresh/Reload MUI WPF Page when Tab is Changed

I am developing a desktop application using Modern UI for WPF. 我正在使用用于WPF的Modern UI开发桌面应用程序。 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. 当我使用选项卡控制器转到另一个页面时,我想刷新MUI WPF选项卡页面。

Can anyone help me? 谁能帮我?

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. 我不太清楚您的确切意思,但是通过在控件上调用InvalidateVisual()可以强制对其进行视觉刷新,因为这听起来像您拥有的WPF控件不数据更改时不会更新。

Based on the MSDN documentation , this: 根据MSDN文档 ,这是:

Invalidates the rendering of the element, and forces a complete new layout pass. 使元素的呈现无效,并强制执行完整的新布局。 OnRender is called after the layout cycle is completed . 在布局周期完成后调用OnRender

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. 我希望这是有用的。

You can use SelectionChanged event to handle this. 您可以使用SelectionChanged事件来处理此问题。 You can refresh MUI WPF tab page by using SelectionChanged. 您可以使用SelectionChanged刷新MUI WPF选项卡页面。

<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: 然后,您可以在事件中访问每个TabItem:

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

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. MUI包含一个内容导航框架,该框架根据链接uri处理内容的加载,卸载和历史导航。 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. 通过实现FirstFloor.ModernUI.Windows命名空间中可用的IContent接口,使您的内容导航意识。

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;
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM