1
BidirectionalDial tempGauge = new Dial360();

if (chp.DialType.Equals("360")) 
{
    tempGauge = new Dial360();
}
else if (chp.DialType.Equals("180"))
{
    tempGauge = new Dial180North();
}
else if (chp.DialType.Equals("90"))
{
    tempGauge = new Dial90SouthEast();
}

tempGauge.FontSize = GaugeDialProperty.getGaugeFontSize(chp.DialType, chp.MaxVal);

GetGaugeFontSize返回一个整数,但它仅适用于Dial360. 它不适用于Dial180North并且Dial90SouthEast它们使用默认字体大小。我该如何解决这个问题?

解决方案:

            Grid dg = (Grid)tempGauge.Content;
            foreach (UIElement ui in dg.Children)
            {
                Type elementType = ui.GetType();
                if (elementType.FullName == "System.Windows.Controls.TextBlock")
                {
                    TextBlock tb = (TextBlock)ui;
                    tb.FontSize = fontSize;
                }
            }
4

0 回答 0