Sizing, Positioning, and Transforming Elements

Slides:



Advertisements
Similar presentations
LIS650 lecture 4 Thomas Krichel today CSS Properties –Box properties-- List properties –Table properties-- Classification properties –(Audio.
Advertisements

Use Tables for Layout Control Day 7. You will learn to: Understand Tables Create a Simple Table Modify Your Tables Appearance Create Page Layouts with.
Chapter 3 – Web Design Tables & Page Layout
Panels, Tab Containers Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
2 D and 3 D Graphics and Animations Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
1 Cascading Style Sheets Continued Different kinds of selectors in a style sheet –Simple- Pseudo-Class –Contextual- Pseudo-Element –Class Image Styles.
CSS Layout Crash Course An Advance CSS Tutorial. Inline vs. Block Many HTML elements have a default display setting of Block. Block elements take up the.
CSS level 3. History of CSS CSS level 1 – original CSS CSS level 2 CSS level 2 Revision 1 (CSS2.1) – up to CSS2.1 monolithic structure CSS level 3 – specification.
Introduction to Windows Presentation Foundation (WPF) Dr. Frank McCown COMP 445 – GUI Programming.
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
Mahender Sarangam Having close to 5 years of experience. Working as a Senior Software Engineer in United Health Group. Good Knowledge on C#, ASP.NET,
XP 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
Using HTML to Create Tables in Web pages Connie Lindsey November 2005.
1 The Structure of a Web Table beginning of the table structure first row of three in the table end of the table structure table cells You do not need.
Slide 1 of 83 Table Borders To specify table borders in CSS, use the border property. The example below specifies a black border for table, th, and td.
Principles of Web Design 6 th Edition Chapter 7 – Page Layouts.
ITP 104.  While you can do things like this:  Better to use styles instead:
1 Intro XAML Attribute syntax & property syntax Panels Reusable resources Controls Data binding Steen Jensen, spring 2014.
CSS The Definitive Guide Chapter 8.  Allows one to define borders for  paragraphs  headings  divs  anchors  images  and more.
Layout Managers A layout manager is an object that determines the way that components are arranged in a container There are several predefined layout managers.
CHAPTER 10 Formatting Tables and Forms. Using Tables the Right Way  HTML and XHTML have a LOT of tags dedicated to building a table  If you have only.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
 Website development process  CSS  Javascript.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Tutorial 7.
Tables 23 rd February. What XHTML have we done so far? Hyperlinks & anchors - XHTML supports 3 types of lists:  Ordered – +  Unordered – +  Definition.
© 2010 Delmar, Cengage Learning Chapter 3 Setting Up A Document.
Tutorial #6 – Creating Fixed Width Layouts. Tutorial #5 Review – Box Model Every html element is surround by a box Content, Padding, Border, Margin Can.
1. Chapter 10 Managing and Printing Documents 3 Working with Files and Printing You can open multiple documents in Word. When multiple documents are.
CSS Layout Arrangement and Positioning of the HTML Elements Svetlin Nakov Technical Trainer Software University
Rujchai Ung-arunyawee Department of Computer Engineering Khon Kaen University.
Layout With Panels. Canvas Most basic panel Position with explicit coordinates Attached properties: Left, Top, Right, Bottom HorizontalAlignment and VerticalAlignment.
CRSD Technology Training Tony Judice. Quick Access Toolbar – can be modifiedSave as… allows you to save the file to a different location and also as an.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
Computer Graphics Matrices
CONTROLLING Page layout
Sizing, Positioning, and Transforming Elements.
V 1.0 Programming III. Visual/FrameworkElement descendants.
CS 120: Introduction to Web Programming Lecture 10: Extra Features and Website Design Part 1 Tarik Booker CS 120 California State University, Los Angeles.
Layouts To understand various layouts extjs provides, and overview of some commonly used layouts.
Jaime Rodriguez | Microsoft Principal Technical Evangelist Laurent Bugnion | IdentityMine Senior Director XAML Deep Dive for Windows & Windows Phone Apps.
Laying out Elements with CSS
Working with Cascading Style Sheets
Java FX: Scene Builder.
CSS Box Model.
CSS Box Model.
Cascading Style Sheets Boxes
CSS Layouts: Grouping Elements
Windows Presentation Foundation Layout with Panels
Building a User Interface with Forms
Modern Programming Language Java
Chap 7. Building Java Graphical User Interfaces
Layout Managers A layout manager is an object that determines the way that components are arranged in a container There are several predefined layout managers.
Graphical User Interfaces -- Introduction
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Layouts AKEEL AHMED.
CSS Box Model.
Tutorial 3 – Creating a Multiple-Page Report
Cascading Style Sheets Color and Font Properties
Formatting a Workbook Part 1
Responsive Framework.
DREAMWEAVER MX 2004 Chapter 3 Working with Tables
Positioning.
CSS Box Model.
CSS Boxes CS 1150 Fall 2016.
Transformations to Parent Functions
Layout Organization and Management
Positioning Boxes Using CSS
Presentation transcript:

Sizing, Positioning, and Transforming Elements - Santosh Singh

Highlights Controlling Size Controlling Position Applying Transforms This sizing and positioning of controls (and other elements) is called layout. Layout in WPF boils down to interactions between parent elements and their child elements.

Highlights These parent elements that support the arrangement of multiple children are known as panels, and derive from the abstract System.Windows.Controls.Panel class

Positioning and Sizing Size-related properties are shown in blue, and position-related properties are shown in red. In addition, elements can have transforms applied to them (shown in green) that can affect both size and position.

Controlling Size Every time layout occurs (such as when a window is resized), child elements tell their parent panel their desired size. All FrameworkElements have simple Height and Width properties (of type double), but they also have MinHeight, MaxHeight, MinWidth, and MaxWidth properties that can be used to specify a range of acceptable values. The default value of MinHeight and MinWidth is 0, and the default value of MaxHeight and MaxWidth is Double.PositiveInfinity

Controlling Size FrameworkElement's Height and Width have a default value of Double.NaN (Not a Number) FrameworkElement also contains a few more size-related properties: · DesiredSize (inherited from UIElement) · RenderSize (inherited from UIElement) · ActualHeight and ActualWidth

Margin and Padding Margin and Padding are two very similar properties that also are related to an element's size Their only difference is that Margin controls how much extra space gets placed around the outside edges of the element, whereas Padding controls how much extra space gets placed around the inside edges of the element.

Margin and Padding <!-- PADDING: --> <!-- 1 value: The same padding on all four sides: --> <Label Padding="0" Background="Orange">0</Label> <Label Padding="10" Background="Orange">10</Label> <!-- 2 values: Left & Right get the 1st value, Top & Bottom get the 2nd value: --> <Label Padding="20,5" Background="Orange">20,5</Label> <!-- 4 values: Left,Top,Right,Bottom: --> <Label Padding="0,10,20,30“ Background="Orange"> 0,10,20,30</Label> <!-- MARGIN: --> <Border BorderBrush="Black" BorderThickness="1">

Margin and Padding <!-- No margin: --> <Label Background="Aqua">0</Label> </Border> <Border BorderBrush="Black" BorderThickness="1"> <!-- 1 value: The same margin on all four sides: --> <Label Margin="10" Background="Aqua">10</Label> <!-- 2 values: Left & Right get the 1st value, Top & Bottom get the 2nd value: --> <Label Margin="20,5" Background="Aqua">20,5</Label> <!-- 4 values: Left,Top,Right,Bottom: --> <Label Margin="0,10,20,30" Background="Aqua">0,10,20,30</Label>

Margin and Padding

Visibility An element's Visibility property actually isn't Boolean, but rather a three-state System.Windows.Visibility enumeration. · Visible— The element gets rendered and participates in layout. · Collapsed— The element is invisible and does not participate in layout. · Hidden— The element is invisible yet still participates in layout. A Collapsed element effectively has a size of zero, whereas a Hidden element retains its original size.

Visibility <StackPanel Height="100" Background="Aqua"> <Button Visibility="Collapsed">Collapsed Button</Button> <Button>Below a Collapsed Button</Button> </StackPanel> <Button Visibility="Hidden">Hidden Button</Button> <Button>Below a Hidden Button</Button>

Visibility

Controlling Position This section doesn't discuss positioning elements with (X,Y) coordinates. Parent panels define their own unique mechanisms for enabling children to position themselves (via attached properties or simply the order in which children are added to the parent) These mechanisms are related to alignment and a concept called flow direction.

Alignment The HorizontalAlignment and VerticalAlignment properties enable an element to control what it does with any extra space given to it by its parent panel. HorizontalAlignment: Left, Center, Right, and Stretch VerticalAlignment: Top, Center, Bottom, and Stretch <StackPanel> <Button HorizontalAlignment="Left" Background="Red">Left</Button> <Button HorizontalAlignment="Center" Background="Orange">Center</Button> <Button HorizontalAlignment="Right" Background="Yellow">Right</Button> <Button HorizontalAlignment="Stretch" Background="Lime">Stretch</Button> </StackPanel>

Alignment Content Alignment The Control class also has HorizontalContentAlignment and VerticalContentAlignment properties. The default value for HorizontalContentAlignment is Left and the default value for VerticalContentAlignment is Top.

Content Alignment <StackPanel> <Button HorizontalContentAlignment="Left" Background="Red">Left</Button> <Button HorizontalContentAlignment="Center" Background="Orange">Center</Button> <Button HorizontalContentAlignment="Right" Background="Yellow">Right</Button> <Button HorizontalContentAlignment="Stretch" Background="Lime">Stretch</Button> </StackPanel>

Flow Direction FlowDirection is a property on FrameworkElement (and several other classes) that can reverse the way an element's inner content flows The property is of type System.Windows.FlowDirection, with two values: LeftToRight (FrameworkElement's default) and RightToLeft. The idea of FlowDirection is that it should be set to RightToLeft when the current culture corresponds to a language that is read from right-to-left. This reverses the meaning of left and right for settings such as content alignment

Flow Direction <StackPanel> <Button FlowDirection="LeftToRight" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" Height="40" Background="Red">LeftToRight</Button> <Button FlowDirection="RightToLeft" Height="40" Background="Orange">RightToLeft</Button> </StackPanel>

Applying Transforms WPF contains a handful of built-in 2D transform classes (deriving from System.Windows.Media.Transform) that enable you to change the size and position of elements independently from the previously discussed properties. Some Allow rotating and Skewing All FrameworkElements have two properties of type Transform LayoutTransform, which is applied before the element is laid out RenderTransform (inherited from UIElement), which is applied after the layout process has finished

Transforms the difference between applying a transform called Rotate-Transform as a LayoutTransform versus a RenderTransform

Transforms RenderTransformOrigin can be set to a System.Windows.Point, with (0,0) being the default value <Button RenderTransformOrigin="0.5,0.5" Background="Orange"> <Button.RenderTransform> <RotateTransform Angle="45"/> </Button.RenderTransform> Rotated 45° </Button>

Transforms The five built-in 2D transforms, all in the System.Windows.Media namespace: · RotateTransform · ScaleTransform · SkewTransform · TranslateTransform · MatrixTransform

Rotate Transform RotateTransform, demonstrated in the preceding section, rotates an element according to the values of three double properties: · Angle— Angle of rotation, specified in degrees (default value = 0) · CenterX— Horizontal center of rotation (default value = 0) · CenterY— Vertical center of rotation (default value = 0)

Rotate Transform <Button Background="Orange"> <TextBlock RenderTransformOrigin="0.5,0.5"> <TextBlock.RenderTransform> <RotateTransform Angle="45"/> </TextBlock.RenderTransform> 45° </TextBlock> </Button>

Scale Transform ScaleTransform enlarges or shrinks an element horizontally, vertically, or in both directions. This transform has four straightforward double properties: · ScaleX— Multiplier for the element's width (default value = 1) · ScaleY— Multiplier for the element's height (default value = 1) · CenterX— Origin for horizontal scaling (default value = 0) · CenterY— Origin for vertical scaling (default value = 0)

Scale Transform <StackPanel Width="100"> <Button Background="Red">No Scaling</Button> <Button Background="Orange"> <Button.RenderTransform> <ScaleTransform ScaleX="2"/> </Button.RenderTransform> X</Button> <Button Background="Yellow"> <ScaleTransform ScaleX="2" ScaleY="2"/> X + Y</Button> <Button Background="Lime"> <ScaleTransform ScaleY="2"/> Y</Button> </StackPanel>

Scale Transform

Skew Transform SkewTransform slants an element according to the values of four double properties: · AngleX— Amount of horizontal skew (default value = 0) · AngleY— Amount of vertical skew (default value = 0) · CenterX— Origin for horizontal skew (default value = 0) · CenterY— Origin for vertical skew (default value = 0)

Skew Transform

Translate Transform TranslateTransform simply moves an element according to two double properties · X— Amount to move horizontally (default value = 0) · Y— Amount to move vertically (default value = 0) This section is explained in brief in the next chapter.

Matrix Transform MatrixTransform is a low-level mechanism that can be used to create custom 2D transforms. MatrixTransform has a single Matrix property (of type System.Windows.Media.Matrix) representing a 3x3 affine transformation matrix. This basically means that all of the previous transforms (or any combination of them) can also be expressed using MatrixTransform

Matrix Transform The 3x3 matrix has the following values: The final column's values are fixed, but the other six values can be set as properties of the Matrix type (with the same names as shown) or via a constructor that accepts the six values in row-major order.

Combining Transforms <Button> <Button.RenderTransform> TransformGroup is just another Transform-derived class (so it can be used wherever the previous classes are used) whose purpose is to combine child Transform objects. <Button> <Button.RenderTransform> <TransformGroup> <RotateTransform Angle="45"/> <ScaleTransform ScaleX="5" ScaleY="1"/> <SkewTransform AngleX="30"/> </TransformGroup> </Button.RenderTransform> OK </Button>

References Windows Presentation Foundation Unleashed Author – Adam Nathan Publication - SAMS