Silverlight 中的动态 TextBlock 字体大小

发布于 2024-12-20 06:22:22 字数 230 浏览 2 评论 0原文

我目前正在按照 StackOverflow 上的几个答案的建议将 TextBlock 包装在 Viewbox 中,并且按照我想要的方式呈现。但经过一些研究后,我了解到这会影响性能,尤其是当您有相当数量的 TextBlock 使用这种方法时。

在 Silverlight 中是否有更好的方法来做到这一点?

注意:只要可以显示文本,我不介意使用 TextBlock 以外的其他内容。

I am currently wrapping my TextBlock in a Viewbox as suggested by a couple of answers here on StackOverflow, and this renders as I want it to. But after doing a little research, I understand that this hampers performance, especially when you have a decent number of TextBlocks which use this approach.

Is there a better way of doing this in Silverlight?

Note: I don't mind using something other than a TextBlock as long as I can display text.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凶凌 2024-12-27 06:22:22

来自此论坛

// Event handler
private void ControlsSizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
{
    GetFontSize(sender as Control);
}

// Method for font size changes
public static void GetFontSize(Control control)
{
    PropertyInfo info;
    if (control == null || control.ActualHeight <= 0)
        return;
    if(( info = control.GetType().GetProperty("FontSize", typeof(double))) != null)
    {
        info.SetValue(control, 0.7 * control.ActualHeight, null);
    }
}

没有 ViewBox 只涉及魔法计算。线程中还有其他建议,例如更改字体大小并测量几次直到文本适合。

From this forum

// Event handler
private void ControlsSizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
{
    GetFontSize(sender as Control);
}

// Method for font size changes
public static void GetFontSize(Control control)
{
    PropertyInfo info;
    if (control == null || control.ActualHeight <= 0)
        return;
    if(( info = control.GetType().GetProperty("FontSize", typeof(double))) != null)
    {
        info.SetValue(control, 0.7 * control.ActualHeight, null);
    }
}

No ViewBoxes involved just a magic calculation. There are other suggestions in the thread such as changing the font size and measuring a couple of times until the text fits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文