当前位置: 首页 > 知识库问答 >
问题:

导航到其他页面IocContainers和MVVM指示灯

束研
2023-03-14

我正在用MVVM light制作一个WindowsUniversal10应用程序。

但是现在,如果我单击ShowWeatherPage上的项目,我会导航到ShowWeatherDetailPage以获取有关单击项目的更多详细信息。但是我不知道我怎么能做到这一点。你能帮我做这个吗?

下面你可以找到我的代码。我使用IocContainers,每个页面都有一个viewmodel,只有命令绑定。

public class IocContainer
{
    static IocContainer()
    {
        SimpleIoc.Default.Register<ApplicationViewModel>(false);
        SimpleIoc.Default.Register<ShowWeatherViewModel>(false);
        SimpleIoc.Default.Register<ShowWeatherPage>(false);
        SimpleIoc.Default.Register<ShowWeatherDetailPage>(false);
        SimpleIoc.Default.Register<ShowWeatherDetailViewModel>(false);
    }

    public static ShowWeatherPage ShowWeatherPage
    {
        get { return SimpleIoc.Default.GetInstance<ShowWeatherPage>(); }
    }

    public static ShowWeatherViewModel ShowWeatherViewModel
    {
        get { return SimpleIoc.Default.GetInstance<ShowWeatherViewModel>(); }
    }

    public static ApplicationViewModel ApplicationViewModel
    {
        get { return SimpleIoc.Default.GetInstance<ApplicationViewModel>(); }
    }

    public static ShowWeatherDetailPage ShowWeatherDetailPage
    {
        get { return SimpleIoc.Default.GetInstance<ShowWeatherDetailPage>(); }
    }

    public static ShowWeatherDetailViewModel ShowWeatherDetailViewModel
    {
        get { return SimpleIoc.Default.GetInstance<ShowWeatherDetailViewModel>(); }
    }
}


  
  

ApplicationViewModel

public class ApplicationViewModel: ViewModelBaseClass { private Page _currentPage = IocContainer.ShowWeatherPage; public Page CurrentPage { get { return _currentPage; } set { if (_currentPage != value) { _currentPage = value; OnPropertyChanged(); } } } public void Navigate(Page page, object attribs) { CurrentPage = page; } }

ShowWeatherViewModel

public class ShowWeatherViewModel: ViewModelBaseClass { #region variables private Item _selectedVillage = null; #endregion variables #region properties public Item SelectedVillage { get { return _selectedVillage; } set { if (_selectedVillage != value) { _selectedVillage = value; ShowDetailPage(); } } } #endregion properties #region constructor public ShowWeatherViewModel() { } #endregion constructor #region methodes private void ShowDetailPage() { ApplicationViewModel appVm = new ApplicationViewModel(); appVm.Navigate(IocContainer.ShowWeatherPage, SelectedVillage); } #endregion methodes }

ShowWeatherDetailViewModel

public class ShowWeatherDetailViewModel: ViewModelBaseClass { }

ViewModelBaseClass

public class ViewModelBaseClass: INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } }

Pages

MainPage

<Page x:Class="BALaboVoorbeeld.UWP.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:BALaboVoorbeeld.UWP" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" DataContext="{Binding Source={StaticResource ioc}, Path=ApplicationViewModel}" mc:Ignorable="d"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Page Content="{Binding CurrentPage, Mode=TwoWay}" /> </Grid> </Page>

ShowWeatherPage

<Page x:Class="BALaboVoorbeeld.UWP.Pages.ShowWeatherPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:BALaboVoorbeeld.UWP.Pages" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" DataContext="{Binding Source={StaticResource ioc}, Path=ShowWeatherViewModel}" mc:Ignorable="d" Width="450"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100" /> <ColumnDefinition Width="240" /> <ColumnDefinition Width="60" /> <ColumnDefinition Width="1*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="1" /> <RowDefinition Height="40" /> <RowDefinition Height="1*" /> <RowDefinition Height="40" /> </Grid.RowDefinitions> <TextBlock Text="Village:" HorizontalAlignment="Right" Margin="4" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" /> <Button HorizontalAlignment="Stretch" Margin="4" VerticalAlignment="Center" Grid.Row="1" Grid.Column="2" Command="{Binding ShowWeahter}" > <SymbolIcon Symbol="Find" /> </Button> <ListBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" ItemContainerStyle="{StaticResource lstidflt}" SelectedItem="{Binding SelectedVillage, Mode=TwoWay}" ItemTemplate="{StaticResource weatheritemdt}" ItemsSource="{Binding VillageList}" /> </Grid> </Page>

ShowWeatherDetailPage

<Page x:Class="BALaboVoorbeeld.UWP.Pages.ShowWeatherDetailPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:BALaboVoorbeeld.UWP.Pages" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <TextBlock Text="Yes we did it ☻"/> </Grid> </Page>

共有1个答案

何升
2023-03-14

您可以使用MVVM Light的导航服务导航到另一个视图。

http://www.mvvmlight.net/doc/nav1.cshtml

https://marcominerva.wordpress.com/2014/10/10/navigationservice-in-mvvm-light-v5/

 类似资料:
  • Iam正在使用ionic应用程序编辑配置文件和查看配置文件。编辑编辑页面的详细信息后,它将导航到查看配置文件页面。 我希望在导航后刷新查看配置文件页面。 这是editprofile.ts代码: 首先我用下面的导航 通过谷歌搜索,我添加了这个来在导航后刷新视图配置文件 现在发生的是,首先它被重定向到查看个人资料页面,并且没有刷新,它直接重定向到主页,主页被刷新。 请帮助我如何在从“编辑配置文件”页面

  • 在TS文件中 用户详细信息应为 在管理组件中 我的问题是,当单击时,我不会被重定向到页面,但当我从url栏导航到/userdails时,我会看到组件

  • 我正在尝试使用导航组件导航到另一个活动(登录)。 目前,活动1具有导航图1,活动2具有导航图2。 我在中为添加了一个目标。当我导航时,我得到一个空白屏幕,尽管有一个导航图,其中包含另一个片段的起始目标。 没有被调用,或者至少没有被我在中的断点击中。 当我在navGraph1中嵌套navGraph2时,我可以导航到navGraph2中的起始目标片段。navGraph2中的这个起始目的地位于compo

  • 我已使用此(react router 2.0)在路由器上设置了browserHistory: 然后,我尝试使用react router中的browserHistory以编程方式从视图(ala: 这将URL更改为 /map但不会呈现该路由中的组件。我做错了什么?

  • 我的Spring Boot项目遇到问题。当我运行应用程序并转到http://localhost:8086/它重定向到http://localhost:8086/login这不是我想要的页面。 这是我申请的内容。属性文件 我还添加了这个类,它应该打开在 /public/文件夹中找到的index.html文件,如上面的属性中指定的 我是不是做错了什么,还是应该先登录它重定向到的页面?

  • 我有两个页面:home.jsp和stylechoosertable.jsp。jsp有一个指向stylechoosertable.jsp的简单链接。两者都在src-main-webapp-views中。启动应用程序运行良好,加载home.jsp也很好。然而,当我点击链接时,它会转到一个404未找到的页面。 下面是HomeController.java > 仅本地:8080/MySpringMVC/打