简体   繁体   English

在Silverlight应用程序中导航

[英]Navigation in a Silverlight application

I recently got myself into Silverlight and I'm trying to develop an application where it reads data from XML. 最近,我开始涉足Silverlight,并且正在尝试开发一个应用程序,该程序可以从XML读取数据。

My problem is that I have never understood how to actually navigate/make views visible/hidden/collapsed depending on what button the client is clicking. 我的问题是,我从未理解如何根据客户端单击的按钮实际导航/使视图可见/隐藏/折叠。 In example, this project reads the menu structure from a XML file and I'm using an ItemsControl to display the menuitems like this: 例如,该项目从XML文件读取菜单结构,而我正在使用ItemsControl来显示如下菜单项:

<ItemsControl ItemsSource="{Binding MenuItems}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Width="900" Height="40"></StackPanel>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Button Tag="{Binding Url}" Content="{Binding Name}" Click="Button_Click"></Button>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

This code is in my MenuView.xaml (I'm using MVVM by the way) and on my MainPage.xaml I've included the MenuView like this: 这段代码在我的MenuView.xaml中(顺便说一下,我正在使用MVVM),在我的MainPage.xaml中,我已经包括了MenuView,如下所示:

<views:MenuView x:Name="menu" />

Now, when a user click one of the buttons, I need to show the correct view on my mainpage. 现在,当用户单击其中一个按钮时,我需要在主页上显示正确的视图。 The tricky thing (for me at least) is, that the content from the XML file is "of-type", so basically I have these views: 棘手的事情(至少对我来说)是,XML文件中的内容是“类型”的,因此基本上我有以下观点:

  • TextPageView TextPageView
  • NewsPageView NewsPageView

Where the NewsPageView's layout is different than the TextPageView, which is just a regular textpage really. NewsPageView的布局不同于TextPageView的布局,后者实际上只是一个常规的文本页面。

How exactly should I be navigating/hiding/showing these views without using the navigation framework? 使用导航框架的情况下,应该如何导航/隐藏/显示这些视图? :-) :-)

Hope my question is clear, if not - please let me know and I will try to elaborate! 希望我的问题很清楚,如果不是,请告诉我,我将尽力阐述!

Thanks in advance. 提前致谢。

All the best, 祝一切顺利,

Bo

导航框架是您的朋友:)

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

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