-
May 14th, 2009, 06:10 AM
#1
Wpf ??
I want to use WPF to create my next application, but there doesn't really seem to be support for SDI type interface.
What I want, is a stack panel along the top displaying buttons that are my menu items, stack panel along the left displaying buttons that are my menu options, and the rest of the area for "content".
As the user selects a menu / menu item, I want the content area to display a different view.
Can anyone point me to an article or examply that may help me achieve this??
Mike B
-
May 14th, 2009, 12:32 PM
#2
Re: Wpf ??
What I've done in this situation is to use a tabcontrol with hidden tabs. As a user makes a 'view' selection, the SelectedIndex of the TabControl is changed and a different view is displayed.
For example, the following code has the ability to display 3 different views:
First let's declare the 'hidden' tab control style:
Code:
<Window.Resources>
<Style x:Key="HiddenTabItemStyle" TargetType="{x:Type TabItem}">
<Setter Property="Visibility" Value="Hidden"/>
<Setter Property="Margin" Value="0"/>
</Style>
<Style x:Key="HiddenTabStyle" TargetType="{x:Type TabControl}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Margin" Value="0,-15,0,0"/>
</Style>
</Window.Resources>
Next use the tabstyles in a tabcontrol that contains 3 different views
Code:
<TabControl x:Name="_viewContainer"
SelectedIndex="{Binding Path=ViewModeId}"
Background="Transparent"
Style="{StaticResource HiddenTabStyle}" BorderBrush="Transparent" >
<TabItem Background="Transparent" Style="{StaticResource HiddenTabItemStyle}">
<acc:AutomaticView x:Name="_automaticView" />
</TabItem>
<TabItem Background="Transparent" Style="{StaticResource HiddenTabItemStyle}">
<acc:EditView x:Name="_editView" />
</TabItem>
<TabItem Background="Transparent" Style="{StaticResource HiddenTabItemStyle}">
<acc:ManualView x:Name="_manualView" />
</TabItem>
</TabControl>
In the above code, when the ViewModeId property changes, the new view gets loaded.
-
May 14th, 2009, 08:25 PM
#3
Re: Wpf ??
Originally Posted by Arjay
What I've done in this situation is to use a tabcontrol with hidden tabs. As a user makes a 'view' selection, the SelectedIndex of the TabControl is changed and a different view is displayed.
For example, the following code has the ability to display 3 different views:
First let's declare the 'hidden' tab control style:
Code:
<Window.Resources>
<Style x:Key="HiddenTabItemStyle" TargetType="{x:Type TabItem}">
<Setter Property="Visibility" Value="Hidden"/>
<Setter Property="Margin" Value="0"/>
</Style>
<Style x:Key="HiddenTabStyle" TargetType="{x:Type TabControl}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Margin" Value="0,-15,0,0"/>
</Style>
</Window.Resources>
Next use the tabstyles in a tabcontrol that contains 3 different views
Code:
<TabControl x:Name="_viewContainer"
SelectedIndex="{Binding Path=ViewModeId}"
Background="Transparent"
Style="{StaticResource HiddenTabStyle}" BorderBrush="Transparent" >
<TabItem Background="Transparent" Style="{StaticResource HiddenTabItemStyle}">
<acc:AutomaticView x:Name="_automaticView" />
</TabItem>
<TabItem Background="Transparent" Style="{StaticResource HiddenTabItemStyle}">
<acc:EditView x:Name="_editView" />
</TabItem>
<TabItem Background="Transparent" Style="{StaticResource HiddenTabItemStyle}">
<acc:ManualView x:Name="_manualView" />
</TabItem>
</TabControl>
In the above code, when the ViewModeId property changes, the new view gets loaded.
Arjay,
Thanks for the reply. So, this is simply to change the views correct? How do you create the views to show? Do you use a UserControl or form without border, or....
Also, I think I have found another solution as well, ProjectTrackers from CSLA library. Not yet sure which is the better of the two..... In that sample he:
1) Places a DockPanel on the main window.
2) Uses a list box with items (TextBlock) as the menu.
3) In the AXML he attaches (?) a hyperlink which points to a delegate in the main window .cs file.
4) This delegate then clears the DockPanel and shows the appropriate view.
The views in this sample are UserControl objects. Just thought you may have 2 cents to put in regarding this method.
Thanks again,
Mike B
-
May 14th, 2009, 09:34 PM
#4
Re: Wpf ??
Originally Posted by MikeB
Arjay,
Thanks for the reply. So, this is simply to change the views correct? How do you create the views to show? Do you use a UserControl or form without border, or....
Yeah, to create the views you'll see a line such as the following as children of each TabItem:
Code:
<acc:AutomaticView x:Name="_automaticView" />
Those are user controls located in another control library. I actually pass the data context of the main control (which is set to my view model) and pass it to each of the views. This allows me to access the data of my model from each of the views (ie. UserControls).
Originally Posted by MikeB
Also, I think I have found another solution as well, ProjectTrackers from CSLA library. Not yet sure which is the better of the two..... In that sample he:
1) Places a DockPanel on the main window.
2) Uses a list box with items (TextBlock) as the menu.
3) In the AXML he attaches (?) a hyperlink which points to a delegate in the main window .cs file.
4) This delegate then clears the DockPanel and shows the appropriate view.
The views in this sample are UserControl objects. Just thought you may have 2 cents to put in regarding this method.
I am familiar with the CSLA framework which btw has had a long history starting with VB, VB.Net, C# and looks like now updated to WPF. The project trackers approach is fine. The approach I've suggested potentially can do all the switching code in xaml (as opposed some wire up in the code behind) which I prefer.
-
May 15th, 2009, 04:13 AM
#5
Re: Wpf ??
Originally Posted by Arjay
The approach I've suggested potentially can do all the switching code in xaml (as opposed some wire up in the code behind) which I prefer.
Well, that makes sence.... I am sure I will have more questions as I dig a little deeper....
Thanks
Mike B
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|