Creating wheels, mimicking WPF's UI framework, is not perfect ...

Source: Internet
Author: User

WTF (temporarily named, casually up = _=), mimicking the framework of WPF, is yet to be perfected, with only simple underlying elements that support data binding. Although Mono is supported, Mono has a bug

Writing this is just a hobby, it doesn't make much sense, if the UI framework is perfect, how many people are willing to use it? After all, there is WPF on Windows, and C # has a few cross-platform requirements. I am not familiar with WPF, and to be perfect, there is much to write about. A whole bunch of common controls and designers. But I do not use XML to describe, but directly in C # to define, the designer directly generated C # code, because I think, if there is a strong designer, write XML is redundant, and parsing XML also affect performance, for WPF, I think the XAML is too verbose.

Wtfobject is equivalent to DependencyObject dependent objects in WPF. Inherit the object of the class, all properties by default are dependency properties

Attribute notation:

        /// <summary>        /// The data context        of the binding /// </summary>        [UIPropertyMetadata (nulltrue)]          Public Virtual Object DataContext        {            getreturn getvalue<object>();}             Set {SetValue (value);}        }

Attributes can be one of PropertyMetadata or UIPropertyMetadata, and the default values can be set by these two attributes. If these two attributes are not added, the default value is null or 0

If the default value is a complex property type, you can override Onoverridemetadata to set the

       protected Override void Onoverridemetadata (overridemetadata overridepropertys)       {            base. Onoverridemetadata (overridepropertys);            Overridepropertys.override ("strokestyle"new Uipropertymetadataattribute (new Stroke (1falsetrue ));        }

Data binding:

varbind = label["Text"] <="Test";//right-to-left data binding, data source is a property of DataContextvarbind = label["Text"] >="Test";//left-to-right data binding, data source is a property of DataContextvarbind = label["Text"] !="Test";//Right to leftdata binding, passed only once, data source is a property of DataContextvarbind = label["Text"] =="Test";//bidirectional binding, the data source is an attribute of DataContext, and bidirectional binding requires an object implementation INotifyPropertyChanged varbind = label["Text"] <= button["Test"];//right-to-left data bindingvarbind = label["Text"] >= button["Test"];//left-to-right data bindingvarbind = label["Text"]! = button["Test"];//right-to-left data binding, passing only oncevarbind = label["Text"] = = button["Test"];//two-way binding

Command bindings:

Call method when event trigger or property changes

Label. AddCommand ("MouseDown","button1_click","  commandcontext ", Wtf.Windows.CommandParameter.EventArgs);
        /// <summary>        ///Add processing commands, command methods on objects of Commandcontext or other properties/// </summary>        /// <param name= "EventName" >Event name or property name that is triggered</param>        /// <param name= "methodName" > command Method Name</param>        /// <param name= "propertyname" > Command object is located in the Property name</param>        /// <param name= "PS" >method parameters, which can be custom data or data for related properties or events</param>         Public voidAddCommand (stringEventName,stringMethodName,stringPropertyName ="Commandcontext",params Object[] PS)

Some types of implicit conversions

Brush, Color: "#0000ff" "#ff0000ff" "255,255,255" "255,255,255,255" colour string conversion, in order is r,g,b, a,r,g,b

Floatvalue: "10%" "+" "Zero" "Auto" 100 100.5 number or percent string conversion, shaping, floating-point data auto-conversion

Trigger Style Example

button mouse action effect, mouse move in move out press background color change

Styling.trigger hover =NewStyling.trigger {Condition = Styling.Conditions.Equals, property ="IsMouseOver", Value =true }; Hover. Setters.add ("Background", Drawing.Brush.Parse ("#ff0000")); Styling.trigger Normal=NewStyling.trigger {}; Normal. Setters.add ("Background", Drawing.Brush.Parse ("#00ff00")); Styling.trigger Press=NewStyling.trigger {Condition = Styling.Conditions.Equals, property ="ismousecaptured", Value =true }; Press. Setters.add ("Background", Drawing.Brush.Parse ("#ffff00")); Label.            Triggers.add (normal); Label.            Triggers.add (hover); Label.            Triggers.add (press); Label. MouseDown+=Delegate{label.            CaptureMouse ();            }; Label. MouseUp+=Delegate{label.            Releasemousecapture (); };

The value precedence of the Wtfobject property setting is higher than the value of the trigger style setting, so when you set the property value, the trigger style may not have an effect

Add UI elements, UI elements can be nested with each other

            varRoot =testcontrol1.rootuielement; Root. Foreground="#ff0000"; Root. FontFamily="Microsoft Ya-Black"; Root. FontSize= -; Root.            Children.add (label); Root. Children.add (NewWindows.Shapes.Ellipse {Stroke="#0000ff", Fill=" White", Width= +, Height= -, MarginLeft= -, MarginTop= -            }); Root. Children.add (NewWindows.Shapes.Ellipse {Stroke="#0000ff", Fill=" White", Width= +, Height= -, MarginRight= "30% ", MarginTop= -            }); 

element layout, support percent layout, margin adjust positioning, default center.

Trigger-bound animations

            vart =NewTrigger (); Storyboard SS=NewStoryboard (); Ss. Duration=NewTimeSpan (0,0,0,0, -); varTL =NewTimeline (1); Tl. Keyframes.add (Newkeyframe<floatvalue> {property ="Height", Value = -, Ease =NewBounceease (), Animatemode =Animatemode.easein}); Tl. Keyframes.add (Newkeyframe<floatvalue> {property ="Width", Value ="30%", Ease =NewBounceease (), Animatemode =Animatemode.easein}); Tl. Keyframes.add (Newkeyframe<generaltransform> {property ="RenderTransform", Animatemode = animatemode.easeout, Value =Newgeneraltransform {Angle = -}, Ease =Newelasticease ()}); //TL. Keyframes.add (New Keyframe<solidcolorbrush> {property = Shape.fillproperty, Value = ' white '});SS.            Timelines.add (TL); T.property="IsMouseOver"; T.value=true; T.animation=SS; T.setters.add ("Fill", Brush.parse ("#fff")); V.triggers.add (t);

If you write a custom control, inherit Wtf.Windows.Controls.Control and then rewrite InitializeComponent to write the style definition code inside, and if you inherit the changes again, you can override the overwrite.

DLL temporarily not available for download

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.