Skip to content

WPF Application Support

Gary edited this page Mar 12, 2015 · 1 revision

WPF provides a framework for application support in the Sce.Atf.Wpf and Sce.Atf.Wpf.Applications namespaces.

MainWindow Component

MainWindow is a MEF component that provides an application's main window. It is defined in MainWindow.xaml and MainWindow.xaml.cs.

MainWindow is used in the ATF Simple DOM Editor WPF Sample, as seen in its App class's TypeCatalog. That's all you need to do to use MainWindow.

You can use this component as is, or modify it to suit your application.

MainWindow.xaml

Here is MainWindow.xaml:

<Window x:Class="Sce.Atf.Wpf.Controls.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:l="clr-namespace:Sce.Atf.Wpf"
    xmlns:b="clr-namespace:Sce.Atf.Wpf.Behaviors" 
    Height="600" Width="600"
    WindowStartupLocation="Manual"
    AllowDrop="False"
    Style="{DynamicResource {x:Type Window}}"
    b:CS4Options.DisplayMode="True"
    b:CS4Options.UseLayoutRounding="True"
    Name="me"
    >
    <DockPanel Name="dockPanel">
        <Menu DockPanel.Dock="Top" Name="menuBar" 
              ItemsSource="{Binding MainMenuViewModel.Menus, ElementName=me}" 
              Style="{StaticResource ResourceKey={x:Static l:Resources.MenuStyleKey}}"/>
        <ToolBarTray DockPanel.Dock="Top" Name="toolBarTray"  
              Style="{StaticResource ResourceKey={x:Static l:Resources.ToolBarTrayStyleKey}}"/>
        <StatusBar DockPanel.Dock="Bottom" Name="statusBar" 
              MinHeight="16"
              ItemsSource="{Binding StatusItems, ElementName=me}" 
              Style="{StaticResource ResourceKey={x:Static l:Resources.StatusBarStyleKey}}"/>
    </DockPanel>
</Window>

This XAML shows that MainWindow is a System.Windows.Window containing a System.Windows.Controls.DockPanel holding System.Windows.Controls.Menu, System.Windows.Controls.ToolBarTray, and System.Windows.Controls.Primitives.StatusBar controls. Each control has a dependency property for its style, defined in Sce.Atf.Wpf.Resources.

MainWindow.xaml specifies initial values for several Window properties: Height, Width, WindowStartupLocation, and AllowDrop.

MainWindow.xaml also sets several TextOptions dependency properties true: DisplayMode and LayoutRounding. Display Mode uses GDI compatible text metrics; for more information, see WPF 4.0 Text Stack Improvements. Layout Rounding forces the WPF layout system to position elements on pixel boundaries, eliminating many negative side effects of sub-pixel positioning; for details, see Layout Rounding.

MainWindow.xaml.cs

MainWindow.xaml.cs has properties for view models of the application's toolbar and menu. ToolBarViewModel provides various toolbar utilities, such as enumerating items for a given toolbar. MainMenuViewModel has a similar offering for menus. For more information on view models in ATF, see WPF ViewModels in ATF.

The StatusItems property gets and sets items in the StatusBar.

The MainContent property gets or sets the control that represents the main content of the window.

Clone this wiki locally