CPF C# Cross platform desktop UI frame

Series of tutorials

CPF Introductory tutorial ( One )

CPF  Enter into Door tutorial - Data binding and command binding ( Two )

CPF Introductory tutorial - Style and animation ( 3、 ... and )

CPF Introductory tutorial - mapping ( Four )

CPF Introductory tutorial - The use of designer and template library ( 5、 ... and )

CPF Introductory tutorial - Control layout ( 6、 ... and )

CPF Introductory tutorial - Properties and events ( 7、 ... and )

Dependency property

CpfObject amount to WPF Inside DependencyObject Dependent object . Inherits objects of this class , All properties are dependent by default

What's the use of dependency properties ? Support property change notification , Data binding , trigger , Animation and so on .

Attribute writing :

        /// <summary>
/// Bound data context
/// </summary>
[PropertyMetadata(null)]
public virtual object DataContext
{
get { return GetValue<object>(); }
set { SetValue(value); }
} /// <summary>
/// The foreground
/// </summary>
[UIPropertyMetadata(typeof(ViewFill), "Black", UIPropertyOptions.AffectsRender)]
public ViewFill Foreground
{
get { return (ViewFill)GetValue(); }
set { SetValue(value); }
}

Attributes can be PropertyMetadata perhaps UIPropertyMetadata One of them , The default value is recommended to be set through these two features . Without these two features , The default is null perhaps 0, Property cannot be private, Otherwise, subclasses cannot use this property ,

Subclasses cannot use new To override the property in the same way

If it's a complex property type, the default value , This can be done by rewriting OnOverrideMetadata To set up

        protected override void OnOverrideMetadata(OverrideMetadata overridePropertys)
{
base.OnOverrideMetadata(overridePropertys);
overridePropertys.Override("StrokeStyle", new UIPropertyMetadataAttribute(new Stroke(1)));
}

If you don't want to declare a dependency property , Add above [NotCpfProperty]

        [NotCpfProperty]
public bool IsMeasureValid
{
get;
private set;
}

Additional attributes

Special dependency properties , Used to mark special functions

/// <summary>
/// Gets or sets the element row index
/// </summary>
public static Attached<int> RowIndex
{
get { return CpfObject.RegisterAttached(0); }
} Grid.RowIndex(control, 1);// Set the row index with additional attributes var index = Grid.RowIndex(control);// Get additional property values control.Attacheds.Add(Grid.ColumnIndex, 0);
// Setting and binding of additional properties
new Border
{
Attacheds={ { Grid.ColumnIndex, 0,nameof(TabStripPlacement),this}},
}

Compute properties

The calculated properties come from Vue Inside computed  Binding , Read-only property

When SelectValue perhaps TextSize A change in the value of an attribute results in TestComputedProperty Property value changes , There are property notifications available

        [Computed(nameof(SelectValue), nameof(TextSize))]
public string TestComputedProperty
{
get { return SelectValue == null ? "" : SelectValue.ToString() + TextSize; }
}

Property notification

If it's the internal binding of the object itself , Define a method , Add one to it PropertyChanged( The property name of the notification ) Just go , Method parameter must be

(object newValue, object oldValue, PropertyMetadataAttribute attribute)

PropertyChanged You can add more , Equivalent to binding to multiple property notification events

 [PropertyChanged(nameof(MarginBottom))]
[PropertyChanged(nameof(MarginLeft))]
[PropertyChanged(nameof(MarginRight))]
[PropertyChanged(nameof(MarginTop))]
void RegisterMargin(object newValue, object oldValue, PropertyMetadataAttribute attribute)
{ }

Rewriting is generally not recommended OnPropertyChanged To handle attribute change events in a different way

If it's outside , binding PropertyChanged event , Through event data CPFPropertyChangedEventArgs To determine attributes and get attribute data

Event definition

CpfObejct The definition of events in , Weak reference Events , And it's not bound repeatedly

public event EventHandler<RoutedEventArgs> DoubleClick
{
add { AddHandler(value); }
remove { RemoveHandler(value); }
} RaiseEvent(e, nameof(DoubleClick));// Triggering event

Because it is weakly quoted , So we can't use Lambda Way to bind Events , Because it may be recycled, leading to binding invalidation

Like this way of writing this.Click+=(s,e)=>{…};

CPF Introductory tutorial - Properties and events ( 7、 ... and ) More articles about

  1. CPF Introductory tutorial - Data binding and command binding ( Two )

    CPF netcore Cross platform UI frame Series of tutorials CPF Introductory tutorial ( One ) CPF Introductory tutorial - Data binding and command binding ( Two ) Data binding and Wpf similar , Support for two-way binding . Data binding and command binding are UI The basis of separation from business logic ...

  2. Caliburn.Micro Jay's introductory course 4, Event aggregator

    Caliburn.Micro Jay's introductory course 1( Original translation )Caliburn.Micro Jay's introductory course 2 , understand Data Binding and Events( Original translation )Caliburn.Micro Jay's introduction ...

  3. Caliburn.Micro Jay's introductory course 3, Events and parameters

    Caliburn.Micro Jay's introductory course 1( translate )Caliburn.Micro Jay's introductory course 2 , understand Data Binding and Events( translate )Caliburn.Micro Jay's introductory course 3, ...

  4. CPF Introductory tutorial - Style and animation ( 3、 ... and )

    CPF NetCore Cross platform UI frame Series of tutorials CPF Introductory tutorial ( One ) CPF Introductory tutorial - Data binding and command binding ( Two ) CPF Introductory tutorial - Style and animation ( 3、 ... and ) Using styles, you can batch set attributes for internal elements . ...

  5. CPF Introductory tutorial - mapping ( Four )

    CPF NetCore Cross platform UI frame , Added Vlc Support cross platform video playback . Series of tutorials CPF Introductory tutorial ( One ) CPF Introductory tutorial - Data binding and command binding ( Two ) CPF Introductory tutorial - Style and animation ( 3、 ... and ) CPF ...

  6. CPF Introductory tutorial ( One )

    CPF netcore Cross platform UI frame Before development , You need to install VS2019. Why vs2019? because VS2019 Ability to support netcore3.0 above ,netcore3.0 Then we can release the independent program , All the previous ones were just ...

  7. React An introduction to examples (1) Basics API,JSX grammar --hello world

      front   said without doubt ,react It's the hottest framework right now ( Not one of them. ), Understand and learn to use React, It can be said that every front-end engineer now needs . In the front end area , Why is a framework so hot , There are two reasons : Excellent performance , Development ...

  8. Caliburn.Micro Jay's introductory course 6, Screens and Conductors brief introduction

    Caliburn.Micro Jay's introductory course 1( translate )Caliburn.Micro Jay's introductory course 2 , understand Data Binding and Events( translate )Caliburn.Micro Jay's introductory course 3, ...

  9. Caliburn.Micro Jay's introductory course 5,Window Manager Window manager

    Caliburn.Micro Jay's introductory course 1( translate )Caliburn.Micro Jay's introductory course 2 , understand Data Binding and Events( translate )Caliburn.Micro Jay's introductory course 3, ...

  10. Caliburn.Micro Jay's introductory course 2 , understand Data Binding and Events( translate )

    Caliburn.Micro Jay's introductory course 1( translate )Caliburn.Micro Jay's introductory course 2 , understand Data Binding and Events( translate )Caliburn.Micro Jay's introductory course 3, ...

Random recommendation

  1. css3 Selectors ( Two )

    Pick up css3 Selectors ( One ) 8、 ... and . Structural pseudo class selector [:nth-child(n)] :nth-child(n) Selectors are used to match one or more specific child elements of a parent element , and jquery In the same . among "n&qu ...

  2. More detail PHP Generate static pages tutorial

    One ,PHP Scripts and dynamic pages . PHP A script is a server-side script program , It can be connected with HTML File mix , You can also use classes , Function encapsulation, etc , Process user requests in the form of templates . Either way , Its basic principle is like this . By guest ...

  3. HANA Studio Turn on the system display Secure storage is locked

    I've been using it well before , Open today HANA Studio All of a sudden, one of the systems is gone : Tips :‘Secure storage is locked’ I'll take the next one Unlocked No reaction , Right click has no function . as follows ...

  4. AC automata project

    // There are several pattern strings in the target string //==================== #include <stdio.h> #include <algorithm> #include ...

  5. window The configuration SSH Connect GitHub、GitHub To configure ssh key( turn )

    from :http://jingyan.baidu.com/article/a65957f4e91ccf24e77f9b11.html This experience is divided into two parts : Part I Introduction : stay windows Pass through msysGit ...

  6. C# - Redefine equality for reference types

    In general, the equality of reference types should not be redefined / Rewrite the . For example, two variables of reference type x and y, If you write like this :if(x == y) {...}, So everyone knows , This compares the equality of references . But in a few cases , also ...

  7. Python Programming practice : Square formatting

    Problem description : Get an integer entered by the user N, Calculation N The square value of : Results using width 20 Character mode center output , The minus sign is used for the spare characters (-) fill . If the result is more than 20 Characters , The width of the result shall prevail . Example : Source code : a = int(input ...

  8. Go Language function signature

    Use type Keyword , Function type variables can also be used as function parameters or return values . I think it's an advanced skill , Beginners may need a lot of code to achieve , Advanced can be more general implementation . package main import &quo ...

  9. FFmpeg Soft and hard decoding and multithreading decoding

    One . AVCodecContext Decoding context 1.avcodec_register_all() : Register all decoders 2.AVCodec *avcodec_find_decoder(enum AVCo ...

  10. 【2018.12.10】NOI Simulation game 3

    subject WZJ Answer key I can't write the whole show $FFT$ Series bar …… Autistic T1 A mouthful of milk , I can't write this next time $NTT$ Naked topic, I just fucked myself -_-||| And it's the same as my own simulation problem $set1$ Of $T ...