2000 What you should know about WPF small Posture Basics <63-68 triggers and WPF class logical Structure >

Source: Internet
Author: User

Original: 2000 the WPF small pose basics you should know <63-68 triggers and WPF class logical Structure >

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]

  

#63 trigger triggered property changes can be reset automatically

When trigger changes the value of a property, the property is automatically reset to the initial value if the judgment in trigger is no longer true.

Example: When you set a button mouse over to a dropshadoweffect, you will revert to its original state when you leave the button.

< Window.Resources >      < Style x:Key = "hoverStyle" TargetType = "Button" >          < Style.Triggers >              < Trigger Property = "IsMouseOver" Value = "true" >                  < Setter Property = "Button.Effect" >                      < Setter.Value >                          < DropShadowEffect />                      </ Setter.Value >                  </ Setter >              </ Trigger >          </ Style.Triggers >      </ Style > </ Window.Resources > < StackPanel Orientation = "Horizontal" HorizontalAlignment = "Center" >      < Button Content = "Run" Height = "23" Width = "75" Style = "{StaticResource hoverStyle}" />      < Button Content = "Skip" Height = "23" Width = "75" Style = "{StaticResource hoverStyle}" />      < Button Content = "Jump" Height = "23" Width = "75" Style = "{StaticResource hoverStyle}" /> </ StackPanel >

  

#64 three types of triggers supported by WPF

WPF supports three different kinds of triggers:

<1>. Property Trigger,

1. Triggered when a dependency property is changed

2. Use the property name to customize,

3. Contains setter elements to give one or more dependency property triggers, which can trigger one or more triggeraction when trigger is in the active state or in the inactive state.

<2>. Data Trigger,

1. Triggered when a CLR property is changed

2. Customize by using the Binding keyword,

3. Contains setter elements to give one or more dependency property triggers, which can trigger one or more triggeraction when trigger is in the active state or in the inactive state.

<3>. Event Trigger,

1. Triggered when a routed event is triggered,

2. You can trigger a class derived from triggeraction, such as BeginStoryboard, Soundplayeraction.

3. Multi-use on WPF animations

 #65 dependency property inherits the value assigned to the upper element of the logical tree

The value of a dependency property can come from many different data sources, but in general, values are inherited from the upper-level elements of the logical tree.

This means that when you assign a dependency property value to a high-level element in XAML, a dependency property whose child element has the same name inherits its value.

Here is an example that defines fontstyle in the window element and inherits from the child elements:

<Windowx:class= "Wpfapplication1.mainwindow"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:m= "Clr-namespace:personlib;assembly=personlib"Title= "MainWindow"Height= " the"Width= "525"FontStyle= "Italic">    <StackPanelOrientation= "Vertical">        <ButtonContent= "Run"Height= "All"Width= " the" />        <ButtonContent= "Skip"Height= "All"Width= " the" />        <StackPanelOrientation= "Horizontal">            <LabelContent= "Inside 2nd StackPanel"/>            <LabelContent= "I do my own FontStyle"FontStyle= "Normal"/>        </StackPanel>    </StackPanel></Window>

The label in the child element inherits the font of the italic defined by the window.

#66 dependency property bubbles looking for its inherited value

A UI element looks up for the value it needs to inherit, unless a uniquely defined property is found that will bubble up to find the root element.

Here's an example of a button looking for a FontStyle property value, passing through StackPanel and grid until the window finds its defined value.

<Windowx:class= "Wpfapplication1.mainwindow"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:m= "Clr-namespace:personlib;assembly=personlib"Title= "MainWindow"Height= " the"Width= "525"FontStyle= "Italic"><Grid>    <StackPanelOrientation= "Vertical">        <ButtonContent= "Run"Height= "All"Width= " the" />        <ButtonContent= "Skip"Height= "All"Width= " the" />    </StackPanel></Grid></Window>

#67 class inheritance diagram for UI element controls

  

#68 four base classes for WPF UI elements

There are four base classes, and most UI elements inherit from them, or when you customize some classes yourself, they are inherited from them.

1. ContentElement, 2. FrameworkContentElement, 3. UIElement, 4. FrameworkElement.

  

There will be more tips on the built-in architecture of WPF in the next issue, and I hope to pay more attention to it.

2000 What you should know about WPF small Posture Basics <63-68 triggers and WPF class logical Structure >

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.