2000 What you should know about WPF small Posture Basics <69-73 WPF freeze mechanisms and template>

Source: Internet
Author: User

A person needs to be introduced before the text begins: Sean Sexton. A software engineer from Minnesota Twins. Best of all, he maintained two blogs:2,000things you should Know about C # and 2,000 things you should Know about W PF . He updates one of the most important and easily forgotten knowledge of WPF and C # every day with a short 150-word language like Weibo. I hope I can share it with you.

This series I will not only translate his every tip, but also join his own development of ideas and insights. This series I want to be able to stick with him as well, every day of progress to promote greatness.

Here is a solemn explanation. The series is based on Mr. Sean Sexton's English blog, and Sean Sexton has full copyright and revocation rights.

You can read the article on the WPF tab of this blog earlier.

  [ Small Nine school, dedicated to the ordinary language to describe the extraordinary technology.] If you want to reprint, please indicate the source: Small nine of the academy . cnblogs.com/xfuture]

  

#69 functional units provided by the WPF base class

The four underlying WPF classes inherit directly or indirectly from DependencyObject, providing different capabilities beyond their underlying classes:

  • contentelement adds (inherited from DependencyObject)
    • Input Events and commanding
    • Focus
    • Raise and respond to routed events
    • Animation Support
  • frameworkcontentelement&NBSP; adds (inherited from &NBSP; contentelement )
    • Additional input elements (e.g. tooltips, context menus)
    • storyboards
    • Data Binding
    • Styles
    • property value inheritance
  • UIElement adds (inherited from DependencyObject)
    • Via Visual
      • Hit testing
      • Clipping and coordinate transformations
      • Participation in visual tree via Parent/child relationships
    • Layout Behavior (measure/arrange)
    • Input Events and commanding
    • Focus
    • Raise and respond to routed Events
    • Animation Support
  • FrameworkElement adds (inherited from UIElement)
      • Additional input elements (e.g. tooltips, context menus)
      • Storyboards
      • Data binding
      • Styles
      • Property value Inheritance
      • Support for the logical tree

#70 Two other basic classes: Freezable and animatable

Add two additional members to our class hierarchy:Freezable and animatable

  

  Freezable- implements a "Freezable" mechanism in which objects can provide a frozen, read-only replication.

  animatable- provides the ability to animate objects based on the freeable mechanism.

 #71 Freezable objects to read-only state

An object with the Freeable function is generally in the Read/write state, which can be set to read-only and cannot be changed by the state (Freeze). An object that is frozen (Frozen) is efficient in WPF because it does not need to notify users of changes.

Graphical objects, such as brushes and 3D drawings, also inherit freezable, and the state of the initialization is unfrozen.

If you have an object that you do not want to change, you can use the freeze method to freeze it

  

// Freeze This object, making it read-only (since we don ' TS plan on changing it) if (Thebrush.canfreeze)    thebrush.freeze ();

If you want to change it after freezing, it will produce InvalidOperationException.

 #72 freeze the graphic objects you decide not to modify

For better performance, it is a good idea to freeze processing of some image objects (such as brushes).

Methods that are frozen in your code:

  

// SolidColorBrush, created in XAML, not frozen bool frozen = Tealbrush.isfrozen;    // frozen = False if (tealbrush.canfreeze)     = Tealbrush.isfrozen;         // frozen = True

Methods that are frozen in XAML (to introduce freeze namespaces first)

  

<Windowx:class= "Wpfapplication4.mainwindow"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"Xmlns:po= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"Title= "MainWindow"Height= " the"Width= "525" >    <window.resources>        <SolidColorBrushx:key= "Tealbrush"Color= "Teal"Po:freeze= "True"/>    </window.resources>

#73 Two types of template

There are two types of template:controltemplate and DataTemplate in WPF

The ControlTemplate style is defined as a custom for the control:

<ButtonName= "Btnwithtemplate"Content= "Recreate Me"Foreground= "Blue">    <button.template>        <ControlTemplateTargetType="{x:type Button}">            <StackPanelOrientation= "Horizontal">                <LabelContent="**"Foreground="{TemplateBinding Foreground}"/>                <ButtonContent="{TemplateBinding Content}"Foreground="{TemplateBinding Foreground}"/>                <LabelContent="**"Foreground="{TemplateBinding Foreground}"/>            </StackPanel>        </ControlTemplate>    </button.template></Button>

DataTemplate allows you to add data to the binding, primarily the data that determines the presentation style:

<LabelName= "Lblperson"Content="{Binding}">    <label.contenttemplate>        <DataTemplate>            <Borderborderthickness= "2"BorderBrush= "Darkblue">                <StackPanelOrientation= "Vertical">                    <StackPanelOrientation= "Horizontal">                        <LabelContent="{Binding Path=firstname}"/>                        <LabelContent="{Binding Path=lastname}"FontWeight= "Bold"/>                    </StackPanel>                    <LabelContent="{Binding Path=birthyear}"FontStyle= "Italic"/>                </StackPanel>            </Border>        </DataTemplate>    </label.contenttemplate></Label>

There will be more about WPF application and windows in the next issue, and I hope to pay more attention to it.

2000 What you should know about WPF small Posture Basics <69-73 WPF freeze mechanisms and template>

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.