开发者

Navigation menu for a standalone WPF application

开发者 https://www.devze.com 2023-01-10 14:40 出处:网络
Im just starting out with wpf (in blend 4) and i would like to create an application that has a side menu for changing the content. What i am looking for is something like in word 2010 under the file

Im just starting out with wpf (in blend 4) and i would like to create an application that has a side menu for changing the content. What i am looking for is something like in word 2010 under the file menu. if you click the menu on the left side the content on the right side changes accordingl开发者_如何学Pythony. i have read articles about nesting a page.xaml into a frame and change the frames navigation source to each page. Is this right? When i do that a navigation bar appears at the top. I can get rid of that easy but it seems like i am taking the wrong path at what i want to achieve.

Thanks in advance.


Just to chime in on this, both the TabControl and the Frame-based solutions are somewhat like the extremes of a spectrum. The tab control effects a very close coupling between the tab state and the displayed UI (e.g., you might find it difficult to change to a dialog for which there is no explicit tab item), whereas the frame enables relatively loose coupling, but might be overkill for this scenario, as it aims to support full-blown linear navigation with a history/page stack. (Prism, for example, offers a similar mechanism through its "regions" concept.)

A middle ground could be to have a main "window frame" UI with a placeholder element, and have your individual "pages" derive from UserControl, making them regular UI elements. To switch to a specific page in your UI, you would instantiate (through code or XAML resources) the corresponding user control, and set it as the Content property of the aforementioned placeholder element. (This is basically the same mechanism you mentioned for VB, where you hide/show subforms.)

So there's a range of options to choose from, depending on the actual constraints of your scenario.


The simplest code to do that is creating a TabControl with TabStripPlacement="Left". For example :

        <TabControl TabStripPlacement="Left">
            <TabItem Header="Tab1" />
            <TabItem Header="Tab2" />
            <TabItem Header="Tab3" />
        </TabControl>

You can apply Styles to further change UI, colors and look & feel.

0

精彩评论

暂无评论...
验证码 换一张
取 消