Controls


Windows Presentation Foundation (WPF)

WPF employs XAML which is an XML based language to define and link the UI elements
WPF is based on the DirectX graphics API
Windows Presentation Foundation is a graphical display for windows
A WPF window and all elements inside are measured using device independent units


PresentationFramework.dll
PresentationCore.dll
WindowsBase.dll


Dialog Box

It is possible to use WPF in your Windows Forms solutions
Add a reference to "WindowsFormsIntegration"
Add a reference to "Presentation.Core"
Add a reference to "Presentation.Framework"
Add a reference to "Windows.Base"
Right click on your project and select (Add > New Item)
Choose "UserControl (WPF)" and provide a name of "UserControl1"


System.Windows.Controls.UserControl myusercontrol; 
myusercontrol = new UserControl1();
System.Windows.Window mywindow = new System.Windows.Window
{
   WindowStyle = System.Windows.WindowStyle.ToolWindow,
   Title = "my user control dialog",
   Content = myusercontrol,
   SizeToContent = System.Windows.SizeToContent.WidthAndHeight,
   ResizeMode = System.Windows.ResizeMode.CanResize,
}
mywindow.MinHeight = myusercontrol.MinHeight + 20;
mywindow.MinWidth = myusercontrol.MinWidth + 10;
mywindow.ShowDialog();


The WPF Toolkit

Before a new control makes its way into the WPF libraries of the .NET platform, it typically starts off in the WPF Toolkit.
This toolkit is also a great source of practical components and controls that are not yet available in the normal WPF release cycle.
For example, the WPF Toolkit includes a set of controls for creating bar, pie, bubble, scatter, and line graphs.
To download the WPF Toolkit, review its code, or read its documentation, surf to http://wpf.codeplex.com.


Although you can craft WPF user interfaces by hand or using the graphic-design-oriented tool
Expression Blend, most developers will start in Visual Studio and spend most (or all) of their time there.


Naming Elements

There's one more detail to consider. In your code-behind class, you'll often want to manipulate controls programmatically
To make this possible, the control must include a XAML Name attribute.


Number = Grid.GetLeft(element) 
Grid.SetLeft(element, number)


Property Attributes



Property-Element Syntax

With property-element
syntax, you add a child element with a name in the form Parent.PropertyName. For example, the Grid
has a Background property that allows you to supply a brush that's used to paint the area behind the
controls. If you want to use a complex brush-one more advanced than a solid color fill-you'll need to
add a child tag named Grid.Background, as shown here:
<Grid Name="grid1">
<Grid.Background>
...
</Grid.Background>
...
</Grid>



Markup Extensions



Namespaces

System.Windows.Controls
System.Windows.Media



static resource - this type will be resolved and assigned to the property during the loading of XAML
dynamic resource - bigger performance hit because it looks up the resources every time it is needed


Designer - design aids in the Document View window
Grid Rails - use this to manage rows and columns in a Grid control


Dependency Objects - contain certain additional control properties
These provide additional functionality over the standard properties



Custom Classes and Assemblies

Exposing public types
(xmlns:local="clr-namespace:MyNamespace")




App.xaml

Defines the application and any application resources used to specify the UI which is automatically displayed when the application starts




MainWindow.xaml

The default window that is displayed



Tunnel Events (parent to child)

Also known as preview events
These are routed events which travel from the parent/application down to the element that raised the event



Bubble Events (child to parent)

These are routed events which travel from the element that raised the event up to the parent/application



WPF Units

The measurement system used is dpi (device independent units)



Class Hierarchy

Dispatcher Object
Dependency Object
Visual
UIElement
FrameworkElement
Control - ContentControl / ItemsControl



Layout

A WPF window can only hold a single element
To fit more than one element you need to place a container in your window.


add a panel to the form and dock it
add component PF
create form
add reference to System.Xaml (.NET 4.0)
add reference to WindowsFormsIntegration



(Binding, TemplateBinding, x:Bind) - always use TemplateBinding Generic.xaml Visual States User Controls Dependency Properties



Public Class MyButton : Windows.UI.Xaml.Controls.Button { Public MyButton(): base() { This.DefaultStyleKey = typeof(Windows.UI.Xaml.Controls.Button);
}
}












© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

Next