390 likes | 595 Views
RADNUG.metro.xaml. 7-24-12. Matt Serbinski. @ aquaseal. w hat are we doing?. Learning the basics of XAML syntax, controls, layout databinding styles, control templates, vsm Whats new in WinRT commanding surfaces listview , gridview , flipview , webview semantic zoom. xaml.
E N D
RADNUG.metro.xaml 7-24-12 Matt Serbinski @aquaseal
what are we doing? Learning the basics of XAML syntax, controls, layout databinding styles, control templates, vsm Whats new in WinRT commanding surfaces listview, gridview, flipview, webview semantic zoom xaml metro
what is xaml? XAML => Extensible Application Markup Language initialize objects set properties on objects XAML builds upon XML valid xaml must be valid xml xaml is case-sensitive Generally used for UI development
xaml syntax Object element syntax <Button /> shorthand for: <Button></Button> Property element syntax <Button> <Button.Content> HelloWorld! </Button.Content> </Button> Attribute syntax <Button Content="Hello World!" />
namespaces Use keyword “xmlns:” for the attribute name Prefix with any name you would like Set the value to be “using:” followed by the specific code-backing namespace name xmlns:RADNUG.metro.xaml="using:RADNUG.metro.xaml“ “using:” is new in WinRT If the prefix contains more than 1 period VS 2012 will throw an exception
common xmlns:x namespace constructs x:Key Sets a unique user-defined key for each resource in a ResourceDictionary x:Class Specifies the code namespace and class name for the class that provides code-behind for a XAML page x:Name Specifies a run-time object name for the instance that exists in run-time code after an object element defined in XAML is processed x:Uid Identifies elements that should use localized resources for some of their property values x:Null Specifies null as a value for a property being set through a XAML attribute
xaml intrinsic data types x:Boolean corresponds to the Boolean data type case sensitive x:String corresponds to the String data type encoding for the string defaults to the surrounding XML encoding x:Double corresponds to the Double data type can use text value “NaN” (case sensitive) this is how "Auto" for layout behavior can be stored as a resource value x:Int32 corresponds to the Int32 data type treated as signed can include the minus (“-”) symbol for a negative integer
markup extensions { } {Binding} provides a data-bound property value such that the value is deferred until run time {StaticResource} provides a value for any XAML attribute by evaluating a reference to an already defined resource {TemplateBinding} links the value of a property in a control template to the value of some other exposed property on the templatedcontrol {RelativeSource} provides a means to specify the source of a binding in terms of a relative relationship in the run-time object graph Binding StaticResource TemplateBinding RelativeSource
winRT controls windows.ui.xaml.controls namespace *NEW
winRTtext editing controls: behaviors *Context Menu
panels Look-less containers for displaying child elements StackPanel arranges child elements into a single line that can be oriented horizontally or vertically VirtualizingPanel virtualizes its visual children typically you derive from VirtualizingPanel:VirtualizingStackPanel WrapGrid positions child elements sequentially from left to right or top to bottom when elements extend beyond the container edge, elements are positioned in the next row or column VariableSizedWrapGrid provides a grid-style layout panel where each tile/cell can be a variable size based on content SwapChainBackgroundPanel implements a XAML layout surface target for Microsoft DirectX interoperation scenarios
layout XAML supports fluid layout through: horizontal / vertical stretching of elements HorizontalAlignment=“Stretch” VerticalAlignment=“Stretch” auto sizing elements Width=“Auto” star-sizing Width=“*” XAML supports fixed layout through: setting a pre-defined width / height fast and fluid
demo panels and layout
databinding Provides a simple way for apps to display and interact with data Updates only occur if you implement INotifyPropertyChanged
databinding: binding sources ElementName bind directly to another visual element RelativeSource set binding source relative to the position of the target StaticResource or any object reference Data context is inherited by all child elements set the source property to override data context
databinding: data flow {BindingMode=OneWay} updates the target property when the binding is created. Changes to the source object also propagate to the target {Binding Mode=OneTime} updates the target property when the binding is created {BindingMode=TwoWay} updates either the target or the source object when either changes. When the binding is created, the target property is updated from the source
converters Use code to translate data to match target and source data types Implement IValueConverter implement Convert modifies the source data before passing it to the target implement ConvertBack modifies the target data before passing it to the source
demo databinding
styles, control templates Style contains property setters that can be shared between instances of a type use BasedOn to get styles that have inheritance Control template customize a control's visual structure and visual behavior
vsm: app orientation states <!--Application Orientation States--> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="ApplicationViewStates"> <VisualState x:Name="FullScreenLandscape" /> <VisualState x:Name="Filled" /> <VisualState x:Name="FullScreenPortrait" /> <VisualState x:Name="Snapped" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> Manages states and the logic for transitioning between states for controls
vsm: button example <ControlTemplateTargetType="Button"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualStateGroup.Transitions> <!--Take one half second to transition to the PointerOver state--> <VisualTransition To="PointerOver" GeneratedDuration="0:0:0.5" /> </VisualStateGroup.Transitions> <VisualState x:Name="Normal" /> <!--Change the Background to red--> <VisualState x:Name="PointerOver"> <Storyboard> <ColorAnimationStoryboard.TargetName="ButtonBrush" Storyboard.TargetProperty="Color" To="Red" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid.Background> <SolidColorBrush x:Name="ButtonBrush" Color="Green" /> </Grid.Background> </Grid> </ControlTemplate>
demo style, control templates, vsm
demo list view, grid view, flip view
demo web view
demo semantic zoom
xamlquirks in winRT (release preview) Binding Mode is not TwoWay by default, it is OneWay Loaded is the only RoutedEvent supported in EventTriggers VS Editor reports a WindowsUIXamlBindingWrapper exception when binding anything to a control’s datacontext Set EnableDependentAnimation to true to animate properties that cannot be hardware accelerated New method argument property called CallerMemberNameAttributethat allows you to obtain the method or property name of the caller to the method (great forINotifyPropertyChanged) Missing: TileBrush, RadialGradientBrush, VisualBrush, ImageBrush’sTileModeproperty PriorityBinding, MultiBinding, StringFormat, TargetNullValue
demo XAML Spy
metro.next Next month continue winRT topics Homework work on ideas and storyboards for RADNUG.metro Upload to: http://sdrv.ms/PEYI90
resources – toolkits and tools Callisto https://github.com/timheuer/callisto WinRT Toolkit http://winrtxamltoolkit.codeplex.com XAML Spy http://www.xamlspy.com
resources Many graphics and info was taken from the Windows 8 Camp in a box, Release Preview Edition http://www.microsoft.com/en-us/download/details.aspx?id=29854 Guidelines for snapped and fill views http://msdn.microsoft.com/en-us/library/windows/apps/hh465371.aspx Metro style app guidelines http://msdn.microsoft.com/en-US/library/windows/apps/hh464920
resources XAML overview http://msdn.microsoft.com/en-us/library/windows/apps/Hh700354.aspx Basic XAML syntax guide http://msdn.microsoft.com/en-us/library/windows/apps/hh700351.aspx XAML object mapping specification (MS-XAML-2012) http://msdn.microsoft.com/en-us/library/hh857629(v=prot.10).aspx