Wpf:uielement and the order in which common events are run in FrameworkElement

Source: Internet
Author: User

Test the following events and methods:

UIElement:

OnRender method.

Layoutupdated event.

FrameworkElement:

Onmeasureoverride method.

Onarrangeoverride method.

Loaded event.

Initialized event.

and the dependency property settings in your custom control.



Class Testcontrol:control {public TestControl () {Loaded + = new Routedeventhandler (testcontrol_loade

        D);

        Initialized + = new EventHandler (testcontrol_initialized);

    LayoutUpdated + = new EventHandler (testcontrol_layoutupdated); } #region Prop public static readonly DependencyProperty Propproperty = dependencyproperty.regist ER ("Prop", typeof (BOOL), typeof (TestControl), New Frameworkpropertymetadata ((bool) false, Fra

                Meworkpropertymetadataoptions.affectsrender, New Propertychangedcallback (onpropchanged),

 

    New Coercevaluecallback (Coerceprop));

        public bool Prop {get {return (bool) GetValue (Propproperty);}

    set {SetValue (Propproperty, value);} } private static void Onpropchanged (DependencyObject D, DependencyPropertyChangedEventArgs e) {Debu

    G.writeline ("dp:changed"); } private static ObjectCoerceprop (DependencyObject D, object value) {Debug.WriteLine ("Dp:coerce");

    return value; } #endregion void Testcontrol_layoutupdated (object sender, EventArgs e) {Debug.WriteLine

    ("uielement.layoutupdated"); } void Testcontrol_initialized (object sender, EventArgs e) {Debug.WriteLine ("Frameworkelement.initi

    Alized "); } void Testcontrol_loaded (object sender, RoutedEventArgs e) {Debug.WriteLine ("Frameworkelement.load

    Ed "); } protected override size MeasureOverride (size constraint) {Debug.WriteLine ("Frameworkelement.measu

        Reoverride "); Return base.

    MeasureOverride (constraint); } protected override size Arrangeoverride (size arrangebounds) {Debug.WriteLine ("Frameworkelement.arran

        Geoverride "); Return base.

    Arrangeoverride (Arrangebounds); } protected override void OnRender (DrawingContext drawingcontext)

    {Debug.WriteLine ("Uielement.onrender"); Base.

    OnRender (DrawingContext); }

 

 

}

Then create the control in XAML and set the dependency property:

<loc:testcontrol prop= "True"/>

Results:

Dp:coerce

dp:changed

frameworkelement.initialized

frameworkelement.measureoverride

Frameworkelement.arrangeoverride

uielement.onrender

uielement.layoutupdated

uielement.layoutupdated

frameworkelement.loaded

So, when all properties are initialized, The frameworkelement.initialized will run, and then the controls will start to show, so the two-step layout steps of WPF's measure and arrange begin, and the final onrender is called, and the control is displayed. Then the uielement.layoutupdated control is now displayed, and the last loaded event occurs to represent that all preprocessed items have completed.

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.