Wheels made up! NETCore cross-platform UI framework, CPF

CPF (tentatively named) (Cross platform framework), mimic WPF framework, support for cross-platform UI framework NETCore, the temporary is not perfect, only for testing , only supports Windows and Mac. Support data binding, CSS, animation. . .

Some may say, there is not an open source Avalonia, I tried, but his performance does not work, start slow, high memory usage, with a lot of dll, he was Xaml to describe the UI, I was not provided XAML, C # to write directly, after a design of the directly generate C # code.

 

CpfObject the equivalent of WPF in the DependencyObject dependent objects. Inherited class objects, all property defaults are dependent on property

Properties wording:

. 1          ///  <Summary> 
2          /// binding data context
 . 3          ///  </ Summary> 
. 4          [PropertyMetadata ( null )]
 . 5          public  Object the DataContext
 . 6          {
 . 7              GET { return the GetValue < Object > ();}
 . 8              SET {the SetValue (value);}
 . 9          }

 

The characteristics or attributes may be PropertyMetadata UIPropertyMetadata one, recommended default value set by these two characteristics. If you do not add these two properties, that the default value is null or 0

If the default value is a complex property types, you can be set by rewriting OnOverrideMetadata

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

 

Additional attributes:

        ///  <Summary> 
        /// Gets or sets the index element row
         ///  </ Summary> 
        public  static Attached < int > the RowIndex 
        { 
            GET { return the RegisterAttached ( 0 );} 
        } 

Grid.RowIndex (Control, . 1 ); / / the added attribute row index provided 
var index = Grid.RowIndex (Control); // Get additional attribute values

Data Binding:

var the bind label = [NameOf (Label.text)] <= " the Test " ; // right to left binding data, the data source is a property DataContext 
var the bind label = [ " the Text " ]> = " the Test " ; // binding data left to right, the data source is a property DataContext 
var the bind label = [ " the Text " ] =! " the Test " ; // left to right binding data is transmitted only once, the data source is a property DataContext 
var the bind = label [ " the Text " ] == " the Test " ; //Bidirectional binding data source is DataContext attribute object is required to achieve two-way binding the INotifyPropertyChanged 


var the bind label = [NameOf (Label.text)] <= Button [ " the Test " ]; // right to left data binding 
var the bind = label [NameOf (Label.text)]> = Button [ " the Test " ]; // left to right, the data binding 
var ! = the bind label [NameOf (Label.text)] = Button [ " the Test " ]; // left binding to the right data, once delivery 
var the bind label = [NameOf (Label.text)] == Button [ " the Test " ]; // way binding 

btn.Bindings.Add (nameof (Button.Content), nameof ( TextBlock.Text), null, BindingMode.OneWay, A => a.ToString ()); // add the binding properties through Bindings, recommended NameOf () is not so easy to wrong

 

Bind command:

When an event triggers or call the method attribute changes

Label.Commands.Add(nameof(Window.MouseDown), nameof(Window.DragMove), Relation.Me.Parent);

new Button
    {
       Width = 20,
        Height = 20,
        MarginRight = 30,
        MarginTop = 5,
        Content = "Test",
        Commands = { { nameof(Button.MouseUp), ()=> { window.WindowState = WindowState.Minimized; } } }
     }

 

Layout System

WPF layout and process similar to the Arrange Measure then, if a custom layout container, can refer to code WPF

Element layout, the percentage of support for layout, margin adjust positioning, centered by default. CSS is equivalent in absolute definition of position: absolute;

MarginLeft , MarginTop, MarginRight, MarginBottom , generally the default value is Auto, when the set value is fixed to the side corresponding to the distance from the parent container margin

 

The Width , the Height , the general default value is Auto, if not set, the actual size is determined by the size of the content or sub-element, or determined by the Margin

new Border { Width = "100%", Height = "100%", Background = "#fff", }

 

Automatic conversion property values:

Width = "100%";
Width = "Auto";
Width = 100;
Background = Color.FromRgb(100,100,100);
Background = "#fff";
Background =image;

 



CSS Styles

Supports simple selector

TextBlock {Foreground: rgb (255,0,0);} select all types of elements TextBlock

.test {Foreground: rgb (255,0,0);} select all elements comprising a test class name, class name attribute by adding Classes

#test {Foreground: rgb (255,0,0);} Name property to select all of the test element

[IsMouseOver = true] {...} Trigger Add

Button TextBlock {...} Button in the offspring of an element TextBox, only supports two

Button> TextBlock {...} Button TextBox direct child element of the element, only supports two

 

Triggers and Animation

.test[IsMouseOver=true]{animation-name:myfirst;animation-duration:1s;animation-iteration-count: 1;}

@keyframes myfirst

{

0%   {Background: #f00;}

25%  {Background: #0ff;}

50%  {Background: #00f;}

100% {Background: #0f0;}

}

LoadStyle loading pattern by the method of the root element, such as Window object

 

Control template:

You want to modify inherited control, and then rewrite the InitializeComponent custom code written on the inside, I do not know how to define? Check the built-in template code, detailed look at the template code compression package of documents, copying the past that he wanted changes

 

Mac developers are not familiar with, under Mac systems also can not enter Chinese, there is no slugger enlighten me, how to call the input method, input method and the opening and closing control input candidate word position

I feel template design is not good enough, as well as data binding can also optimize it. You have any thoughts and ideas to talk about.

 

CPF download

Guess you like

Origin www.cnblogs.com/dskin/p/11740751.html