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