Here are three classes in my project. They work as expected. What I'm not sure of is the passing of the target into style sheet. What is going on is that I want the matrix as a whole to be left-aligned on the screen, but each entry to be centered within its column. The GetHorizontalAlignmentQ method accomplishes that.ExpressionStyleSheet has a whole bunch of other subclasses for styling expressions in various situations.This is currently the only case where the project actually makes use of the fact that targets pass themselves into their style sheets when getting style information. So I'm wondering whether or not that choice makes sense, and if not, what might be a different way to accomplish this type of subtlety. I am planning on expanding my use of style sheets (at the moment they are only used for expressions; no reason not to use them to style other views that have some kind of ViewModel), so it would not be difficult to imagine other cases where properties of the target could be useful.public abstract class StyleSheet<TTarget>{  public abstract HorizontalAlignmentEnum? GetHorizontalAlignmentQ(TTarget target);  public abstract VerticalAlignmentEnum? GetVerticalAlignmentQ(TTarget target);  public abstract Color? GetBackgroundColorQ (TTarget taget);  public abstract PCLFont GetFontQ (TTarget target, float scale = float.NaN);  public abstract Color? GetTextColorQ(TTarget target);  public abstract ThicknessF? GetPaddingQ(TTarget target);  public abstract void Apply(TTarget target);  public abstract LineBreakMode? GetLineBreakModeQ(TTarget target);  public abstract String GetGhostedText(TTarget target);  public abstract Color GetGhostedTextColor(TTarget target);}public class ExpressionStyleSheet: StyleSheet<AbstractExpressionUIState>{  public override void Apply(AbstractExpressionUIState target) {    target.SetStyleSheet(this);  }  public override Color? GetBackgroundColorQ(AbstractExpressionUIState taget) {    return Color.Black;  }  public override Color? GetTextColorQ(AbstractExpressionUIState target) {    return Color.White;  }  public override LineBreakMode? GetLineBreakModeQ(AbstractExpressionUIState target) {    return LineBreakMode.None;  }  public override PCLFont GetFontQ(AbstractExpressionUIState target, float scale = float.NaN) {    return PCLFonts.SmallishEditableExpressionFont(scale);  }  public override ThicknessF? GetPaddingQ(AbstractExpressionUIState target) {    PCLFont font = this.GetFontQ(target);    float topBottom = (0.2f * font.PointSize).RoundToFloat();    ThicknessF r = new ThicknessF (0, topBottom, 0, topBottom);    return r;  }  public override HorizontalAlignmentEnum? GetHorizontalAlignmentQ(AbstractExpressionUIState target) {    return HorizontalAlignmentEnum.Right;  }  public override VerticalAlignmentEnum? GetVerticalAlignmentQ(AbstractExpressionUIState target) {    return VerticalAlignmentEnum.Center;  }  public override Color GetGhostedTextColor(AbstractExpressionUIState target) {    return Color.Gray;  }  public override string GetGhostedText(AbstractExpressionUIState target) {    return ;  }  public virtual void ApplyToAttributedString(AttributedString s, AbstractExpressionUIState state) {    HorizontalAlignmentEnum? hAlignment = this.GetHorizontalAlignmentQ(state);    VerticalAlignmentEnum? vAlignment = this.GetVerticalAlignmentQ(state);    s.HorizontalAlignmentQ = hAlignment;    s.VerticalAlignmentQ = vAlignment;  }}internal class MatrixStyleSheet: ExpressionStyleSheet{  public override Color GetGhostedTextColor(AbstractExpressionUIState target) {    return Color.White;  }  public override string GetGhostedText(AbstractExpressionUIState target) {    return 0;  }  public override HorizontalAlignmentEnum? GetHorizontalAlignmentQ(AbstractExpressionUIState target) {    if (target.IsText) {      return HorizontalAlignmentEnum.Center;    } else {      return HorizontalAlignmentEnum.Left;    }  }  public override VerticalAlignmentEnum? GetVerticalAlignmentQ(AbstractExpressionUIState target) {    return VerticalAlignmentEnum.Center;  }  public override PCLFont GetFontQ(AbstractExpressionUIState target, float scale=1) {    return PCLFonts.TextGridFont(scale);  }}
Should a style sheet object know about its target?
c#;user interface