World War I Windows 10 (75) and World War I 75

Source: Internet
Author: User
Tags baseuri

World War I Windows 10 (75) and World War I 75

[Download source code]


Backwater world war I Windows 10 (75)-Controls (control base class): FrameworkElement-basic knowledge, related events, HorizontalAlignment, VerticalAlignment



Author: webabcd


Introduction
Controls for Windows 10 (control base class-FrameworkElement)

  • Basic knowledge
  • Related Events
  • HorizontalAlignment and verticalignment



Example
1. demonstrate basic knowledge of FrameworkElement
Controls/BaseControl/FrameworkElementDemo/Demo1.xaml

<Page    x:Class="Windows10.Controls.BaseControl.FrameworkElementDemo.Demo1"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:Windows10.Controls.BaseControl.FrameworkElementDemo"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d">    <Grid Background="Orange">        <StackPanel Name="stackPanel" Background="Blue" Margin="100">            <TextBlock Name="lblMsg" Margin="5" />        </StackPanel>    </Grid></Page>

Controls/BaseControl/FrameworkElementDemo/Demo1.xaml. cs

/** FrameworkElement-FrameworkElement (inherited from UIElement, see/Controls/BaseControl/UIElementDemo/) * MinWidth, MinHeight-minimum width and height, default value: 0 * MaxWidth, maxHeight-maximum width and height. The default value is double. positiveInfinity * Width, Height-Width and Height, default value: NaN * ActualWidth, ActualHeight-actual Width and Height, from the RenderSize attribute of UIElement (layout of uwp is a recursive system, for more information, see/MyControls/MyControl2.cs) * Margin-Margin *. It is a Thickness object. You can construct this object on the C # side. * if you set it on The xaml side, the rule is "left, top, right, bottom", "left, up, down", or "top left, right, bottom right ", you can use commas or spaces to separate * Name-Name * FindName () -Find the object * Parent with the specified name on the current page-get the Parent object of the current object * Tag-used to save any object * Language-set or retrieve the Language information of the current element and all its child elements (no actual effect, is a flag.) * BaseUri-obtain the uri address of the xaml page where the current object is located * DataContext-data context (see/Bind/DataContextChanged. xaml) * RequestedTheme-topic (see/Resource/ThemeResourceDemo. xaml. cs) * Resources-Resource Dictionary (see/Resource/ResourceDictionaryDemo. xaml) * Style-Style (see/Controls/UI/Style. xaml) * GetBindingExpression ()-obtains the binding information of the specified attribute (see/Bind/UpdateSourceTrigger. xaml. cs) * SetBinding ()-set binding information (see/Bind/BindingElement. xaml. cs) *** This example demonstrates the basic knowledge of FrameworkElement */using System; using Windows. UI. xaml; using Windows. UI. xaml. controls; namespace Windows10.Controls. baseControl. frameworkElementDemo {public sealed partial class Demo1: Page {public Demo1 () {this. initializeComponent (); this. loaded + = demow.loaded;} private void demow.loaded (object sender, RoutedEventArgs e) {stackPanel. minWidth = 0; stackPanel. minHeight = 0; stackPanel. maxWidth = double. positiveInfinity; stackPanel. maxHeight = double. positiveInfinity; lblMsg. text + = $ "stackPanel. actualWidth: {stackPanel. actualWidth}, stackPanel. actualHeight: {stackPanel. actualHeight} "; lblMsg. text + = Environment. newLine; if (this. findName ("lblMsg") as TextBlock = lblMsg) {lblMsg. text + = "this. findName (\ "lblMsg \") as TextBlock = lblMsg "; lblMsg. text + = Environment. newLine;} if (lblMsg. parent as StackPanel = stackPanel) {lblMsg. text + = "lblMsg. parent as StackPanel = stackPanel "; lblMsg. text + = Environment. newLine;} lblMsg. text + = "BaseUri:" + this. baseUri; lblMsg. text + = Environment. newLine; lblMsg. tag = "I am webabcd"; lblMsg. text + = "lblMsg. tag: "+ lblMsg. tag; lblMsg. text + = Environment. newLine ;}}}


2. Demonstrate events related to FrameworkElement
Controls/BaseControl/FrameworkElementDemo/Demo2.xaml

<Page    x:Class="Windows10.Controls.BaseControl.FrameworkElementDemo.Demo2"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:Windows10.Controls.BaseControl.FrameworkElementDemo"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d">    <Grid Background="Orange">        <StackPanel Name="stackPanel" Background="Blue" Margin="100">            <TextBlock Name="lblMsg" Margin="5" />        </StackPanel>    </Grid></Page>

Controls/BaseControl/FrameworkElementDemo/Demo2.xaml. cs

/** FrameworkElement-FrameworkElement (inherited from UIElement, see/Controls/BaseControl/UIElementDemo/) * events triggered when the data context changes (see/Bind/DataContextChanged. xaml) * Loading-after OnNavigatedTo, the Loading event * Loaded-triggered from the inside to the outside * Unloaded-after OnNavigatedFrom, trigger Unloaded event from external to internal * SizeChanged-events triggered when the size (ActualWidth or ActualHeight) changes, * LayoutUpdated-events triggered when the layout is updated are not triggered when the location is changed, for example, if the size or position is changed, *** this example is used to demonstrate the related events of FrameworkElement */using System; using System. diagnostics; using Windows. UI. xaml; using Windows. UI. xaml. controls; using Windows. UI. xaml. navigation; namespace Windows10.Controls. baseControl. frameworkElementDemo {public sealed partial class Demo2: Page {public Demo2 () {this. initializeComponent (); this. loading + = page_Loading; this. loaded + = page_Loaded; this. unloaded + = page_Unloaded; stackPanel. loading + = stackPanel_Loading; stackPanel. loaded + = stackPanel_Loaded; stackPanel. unloaded + = stackPanel_Unloaded; lblMsg. loading + = lblMsg_Loading; lblMsg. loaded + = lblMsg_Loaded; lblMsg. unloaded + = lblMsg_Unloaded; lblMsg. sizeChanged + = lblMsg_SizeChanged; lblMsg. layoutUpdated + = lblMsg_LayoutUpdated;} protected override void OnNavigatedTo (NavigationEventArgs e) {lblMsg. text + = "OnNavigatedTo"; lblMsg. text + = Environment. newLine;} protected override void OnNavigatingFrom (NavigatingCancelEventArgs e) {Debug. writeLine ("OnNavigatingFrom");} protected override void OnNavigatedFrom (NavigationEventArgs e) {Debug. writeLine ("OnNavigatedFrom");} private void page_Loading (FrameworkElement sender, object args) {lblMsg. text + = "page_Loading"; lblMsg. text + = Environment. newLine;} private void page_Loaded (object sender, RoutedEventArgs e) {lblMsg. text + = "page_Loaded"; lblMsg. text + = Environment. newLine;} private void page_Unloaded (object sender, RoutedEventArgs e) {Debug. writeLine ("page_Unloaded");} private void stackPanel_Loading (FrameworkElement sender, object args) {lblMsg. text + = "stackPanel_Loading"; lblMsg. text + = Environment. newLine;} private void stackPanel_Loaded (object sender, RoutedEventArgs e) {lblMsg. text + = "stackPanel_Loaded"; lblMsg. text + = Environment. newLine;} private void stackPanel_Unloaded (object sender, RoutedEventArgs e) {Debug. writeLine ("stackPanel_Unloaded");} private void lblMsg_Loading (FrameworkElement sender, object args) {lblMsg. text + = "lblMsg_Loading"; lblMsg. text + = Environment. newLine;} private void lblMsg_Loaded (object sender, RoutedEventArgs e) {lblMsg. text + = "lblMsg_Loaded"; lblMsg. text + = Environment. newLine;} private void lblMsg_Unloaded (object sender, RoutedEventArgs e) {Debug. writeLine ("lblMsg_Unloaded");} private void lblMsg_SizeChanged (object sender, SizeChangedEventArgs e) {Debug. writeLine ($ "lblMsg_SizeChanged, previussize: {e. previussize}, NewSize: {e. newSize} "); // Note: if the size of lblMsg is changed here, it will be called cyclically and" Layout cycle detected "will appear during compilation. layout cocould not complete. "Error} private void lblMsg_LayoutUpdated (object sender, object e) {Debug. writeLine ("lblMsg_LayoutUpdated"); // Note: If the Layout of lblMsg is changed here, a loop call will occur and "Layout cycle detected" will appear during compilation. layout cocould not complete. "Error }}}


3. Demonstrate the applications of HorizontalAlignment and verticalignment of FrameworkElement
Controls/BaseControl/FrameworkElementDemo/Demo3.xaml

<Page    x:Class="Windows10.Controls.BaseControl.FrameworkElementDemo.Demo3"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:Windows10.Controls.BaseControl.FrameworkElementDemo"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d">    <Grid Background="Orange">        <StackPanel Name="stackPanel" Background="Blue" Margin="100" VerticalAlignment="Stretch">                        <ComboBox Name="cmbHorizontalAlignment" PlaceholderText="HorizontalAlignment" SelectionChanged="cmbHorizontalAlignment_SelectionChanged" Margin="5">                <ComboBoxItem>Left</ComboBoxItem>                <ComboBoxItem>Center</ComboBoxItem>                <ComboBoxItem>Right</ComboBoxItem>                <ComboBoxItem IsSelected="True">Stretch</ComboBoxItem>            </ComboBox>            <ComboBox Name="cmbVerticalAlignment" PlaceholderText="VerticalAlignment" SelectionChanged="cmbVerticalAlignment_SelectionChanged" Margin="5">                <ComboBoxItem>Top</ComboBoxItem>                <ComboBoxItem>Center</ComboBoxItem>                <ComboBoxItem>Bottom</ComboBoxItem>                <ComboBoxItem IsSelected="True">Stretch</ComboBoxItem>            </ComboBox>                    </StackPanel>    </Grid></Page>

Controls/BaseControl/FrameworkElementDemo/Demo3.xaml. cs

/** FrameworkElement-FrameworkElement (inherited from UIElement, see/Controls/BaseControl/UIElementDemo/) * HorizontalAlignment-horizontal alignment (Left, Center, Right, Stretch) * verticalignment-vertical alignment (Top, Center, Bottom, Stretch) *** this example is used to demonstrate the applications of HorizontalAlignment and verticalignment of FrameworkElement */using System; using Windows. UI. xaml; using Windows. UI. xaml. controls; namespace Windows10.Controls. baseControl. frameworkElementDemo {public sealed partial class Demo3: Page {public Demo3 () {this. initializeComponent ();} private void cmbHorizontalAlignment_SelectionChanged (object sender, SelectionChangedEventArgs e) {stackPanel. horizontalAlignment = (HorizontalAlignment) Enum. parse (typeof (HorizontalAlignment), (e. addedItems [0] as ComboBoxItem ). content. toString ();} private void cmbverticalignment_selectionchanged (object sender, SelectionChangedEventArgs e) {stackPanel. verticalAlignment = (verticalignment) Enum. parse (typeof (verticalignment), (e. addedItems [0] as ComboBoxItem ). content. toString ());}}}



OK
[Download source code]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.