WPF MVVM Framework, VM interface write control

Source: Internet
Author: User

MVVM is normal in the view page write style, ViewModel page write logic, but sometimes pure in the view page write style does not meet the requirements. My recent project was met, so I can only write the style control on the VM page and then bind to the View page.

Look at the picture first

Various taxes need to change, of course, not for this reason in the VM page write style, but because the different taxes are red, the corresponding "" is black.

In the TextBlock with the Run property to add the variable, and to add color to run is unified, so you can only use three run to set the "" "," tax "," "", but the foreground has no way to parse, so you can only use the VM page writing style.

Field

        Private TextBlock TextBlock;          Public TextBlock TextBlock        {            getreturn  textBlock;}             Set {TextBlock = value;            raisePropertyChanged ("TextBlock");            }        }

TextBlock style under VM

TextBlock TextBlock =NewTextBlock (); TextBlock. TextWrapping=Textwrapping.wrap;textblock. HorizontalAlignment=Horizontalalignment.center;textblock. Margin=NewThickness ( -,0, -,0); TextBlock. FontSize= -; TextBlock. HorizontalAlignment=Horizontalalignment.left;textblock. VerticalAlignment=Verticalalignment.top; Brushconverter Brushconverter=NewBrushconverter (); Brush Blackbrush= (Brush) brushconverter.convertfromstring ("#2c2c2c"); Brush Redbrush= (Brush) brushconverter.convertfromstring ("#a80301"); TextBlock. Foreground=Blackbrush;textblock. Inlines.add (NewRun () {Text ="       ", Foreground =brushes.red}); TextBlock. Inlines.add ("you have this month"); for(inti =0; i < Mess.count; i++) {TextBlock. Inlines.add (NewRun () {Text =""", Foreground =Blackbrush}); TextBlock. Inlines.add (NewRun {Text = Mess[i]. ToString (), Foreground =Redbrush}); TextBlock. Inlines.add (NewRun () {Text =""", Foreground =Blackbrush});} TextBlock. Inlines.add ("the tax (fee) species has not yet been declared, please declare it within the levy period. "); TextBlock= TextBlock;

XAML page write a scrollviewer to receive it.

<Content= "{Binding TextBlock}"  horizontalscrollbarvisibility= "Disabled"  verticalscrollbarvisibility= "Auto" />

WPF MVVM Framework, VM interface write control

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.