c# - Conditional Styling In Silverlight? -


I'm fine with standard control style in Silverlight, while I recently used more dynamic methods to display data Has started to do. Items Control is a collection of links I'm working with again.

The problem I have is that each link is colorally colored, one red, one blue, one green, etc. Is there a way to style these items without sacrificing the dynamics of controlling an item with a data template?

I did this on a property of visual model through a simple converter, for example You had a boolean property that you wanted to control the style you could. / P>

  public class BoolToStyleConverter: IValueConverter {public style TrueStyle {get; Set; } Public style FalseStyle {get; Set; } #region IValueConverter Member Convert Public Commands (type object type, type targetType, object parameter, System.Globalization.CultureInfo culture) {return ((bool value))? TrueStyle: FalseStyle; } Public Object Convertback (type object type, type target type, object parameter, system globalization. Culture info culture) {new non imulated expansion (); } #endregion}  

Then as a resource, you will define your two styles ...

  General: BoolToStyleConverter x: key = "BoldTextConverter "& Gt; & Lt; Common: BoolToStyleConverter.TrueStyle & gt; & Lt; Style TargetType = "TextBlock" & gt; & Lt; Setter property = "fontwhite" value = "bold" & gt; & Lt; / Setter & gt; & Lt; / Style & gt; & Lt; / Common: BoolToStyleConverter.TrueStyle & gt; & Lt; Common: BoolToStyleConverter.FalseStyle & gt; & Lt; Style TargetType = "TextBlock" & gt; & Lt; Setter property = "fontwhite" value = "normal" & gt; & Lt; / Setter & gt; & Lt; / Style & gt; & Lt; / Common: BoolToStyleConverter.FalseStyle & gt; & Lt; / Common: BoolToStyleConverter & gt;  

Then you apply it to your object like this ...

   

ViewConfirmed where viewmodel has a boolean property, it will also keep the style in sync if isConfirmed changes in property.

If you want to use a more complex situation than boolean, then you can always create a dictionary of objects of the styles in your converter and then do a look of the converter, but I have found that In most cases, booleans usually work.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -