Hello cSharpies,
I'm building my 1st WPF app and I'd like to get off to a good start, so
experienced advice I'm soliciting.
The application is an explorer like tool with two (2) main sections: 1)
a TreeView on the left and 2) a work Grid on the right (see XAML example
below.) The TreeView will display a hierarchy of Groups and Items; there
may be 1 or more Groups with the same set of Items. Selecting an Item
from the TreeView will display a set of controls in the work Grid. Each
Item's work Grid controls will be different. The same Items from
different groups will have the same work Grid, with different (bound) data.
For a Group and it's Items, I'd like to be able do the layout with the
designer and then use the resulting XAML as a sort of template along
with a class - having a class method load the template at runtime.
Questions:
1. Is this possible and/or advisable? If possible, how?
2. Can the XAML template be pre-compiled in some way to speed loading?
Thanks,
Bill
Example XAML:
<Window x:Class="WpfApp lication1.Windo w1"
xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
Height="370" Width="579"
HorizontalAlign ment="Stretch" VerticalAlignme nt="Stretch">
<DockPanel
Height="Auto" Name="dockPanel 1" Width="Auto">
<StatusBar
Height="23" Name="statusBar "
Width="Auto" VerticalAlignme nt="Bottom"
DockPanel.Dock= "Bottom" />
<Menu Height="22" Name="menu1"
Width="Auto" VerticalAlignme nt="Top"
DockPanel.Dock= "Top">
<MenuItem Header="File">
<MenuItem Name="MenuFileE xit"
Header="Exit" Click="MenuFile Exit_Click" />
</MenuItem>
</Menu>
<Grid Height="Auto" Name="grid" Width="Auto">
<Grid.ColumnDef initions>
<ColumnDefiniti on Width="1*"/>
<ColumnDefiniti on Width="3"/>
<ColumnDefiniti on Width="2*"/>
</Grid.ColumnDefi nitions>
<TreeView
Name="treeView" Height="Auto"
Grid.Column="0" Width="Auto">
<TreeViewItem Name="tviGroup" Header="Plant" >
<TreeViewItem Name="tviGroupI tem1" Header="Item2" />
<TreeViewItem Name="tviGroupI tem2" Header="Item2" />
<TreeViewItem Name="tviGroupI tem3" Header="Item3" />
<TreeViewItem Name="tviGroupI tem4" Header="Item4" />
</TreeViewItem>
</TreeView>
<GridSplitter
Name="gridSplit ter" Grid.Column="1"
HorizontalAlign ment="Stretch" />
<Grid
Name="workGrid"
Height="Auto" Width="Auto" Grid.Column="2" >
</Grid>
</Grid>
</DockPanel>
</Window>
I'm building my 1st WPF app and I'd like to get off to a good start, so
experienced advice I'm soliciting.
The application is an explorer like tool with two (2) main sections: 1)
a TreeView on the left and 2) a work Grid on the right (see XAML example
below.) The TreeView will display a hierarchy of Groups and Items; there
may be 1 or more Groups with the same set of Items. Selecting an Item
from the TreeView will display a set of controls in the work Grid. Each
Item's work Grid controls will be different. The same Items from
different groups will have the same work Grid, with different (bound) data.
For a Group and it's Items, I'd like to be able do the layout with the
designer and then use the resulting XAML as a sort of template along
with a class - having a class method load the template at runtime.
Questions:
1. Is this possible and/or advisable? If possible, how?
2. Can the XAML template be pre-compiled in some way to speed loading?
Thanks,
Bill
Example XAML:
<Window x:Class="WpfApp lication1.Windo w1"
xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
Height="370" Width="579"
HorizontalAlign ment="Stretch" VerticalAlignme nt="Stretch">
<DockPanel
Height="Auto" Name="dockPanel 1" Width="Auto">
<StatusBar
Height="23" Name="statusBar "
Width="Auto" VerticalAlignme nt="Bottom"
DockPanel.Dock= "Bottom" />
<Menu Height="22" Name="menu1"
Width="Auto" VerticalAlignme nt="Top"
DockPanel.Dock= "Top">
<MenuItem Header="File">
<MenuItem Name="MenuFileE xit"
Header="Exit" Click="MenuFile Exit_Click" />
</MenuItem>
</Menu>
<Grid Height="Auto" Name="grid" Width="Auto">
<Grid.ColumnDef initions>
<ColumnDefiniti on Width="1*"/>
<ColumnDefiniti on Width="3"/>
<ColumnDefiniti on Width="2*"/>
</Grid.ColumnDefi nitions>
<TreeView
Name="treeView" Height="Auto"
Grid.Column="0" Width="Auto">
<TreeViewItem Name="tviGroup" Header="Plant" >
<TreeViewItem Name="tviGroupI tem1" Header="Item2" />
<TreeViewItem Name="tviGroupI tem2" Header="Item2" />
<TreeViewItem Name="tviGroupI tem3" Header="Item3" />
<TreeViewItem Name="tviGroupI tem4" Header="Item4" />
</TreeViewItem>
</TreeView>
<GridSplitter
Name="gridSplit ter" Grid.Column="1"
HorizontalAlign ment="Stretch" />
<Grid
Name="workGrid"
Height="Auto" Width="Auto" Grid.Column="2" >
</Grid>
</Grid>
</DockPanel>
</Window>
Comment