我目前正在按照StackOverflow上的一些答案建议,将我的TextBlock包装在一个Viewbox中,这样渲染效果很好。但是经过一些研究,我了解到这会影响性能,特别是当您有相当数量的使用此方法的TextBlock时。
在Silverlight中有更好的方法吗?
注意: 只要我可以显示文本,我不介意使用除TextBlock以外的其他东西。
我目前正在按照StackOverflow上的一些答案建议,将我的TextBlock包装在一个Viewbox中,这样渲染效果很好。但是经过一些研究,我了解到这会影响性能,特别是当您有相当数量的使用此方法的TextBlock时。
在Silverlight中有更好的方法吗?
注意: 只要我可以显示文本,我不介意使用除TextBlock以外的其他东西。
// 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);
}
}
没有涉及到ViewBoxes,只是一个神奇的计算。线程中还有其他建议,例如更改字体大小并测量几次,直到文本适合。
FontSize
绑定到视图中的另一个元素或视图模型中的属性。 - ChrisFFontSize="{Binding ElementName=YourGrid, Path=ActualHeight, Converter={StaticResource myConverter}"
转换器将使用网格(例如)的ActualHeight
并对其进行任何所需的操作 - 使用相对计算。更多信息 - http://www.chrisforman.me.uk/2011/05/a-nifty-silverlight-feature/. 不确定是否符合您的要求,因此这不是一个答案(但可能有帮助)。 - ChrisFActualWidth
不会改变。我只是在这里举例使用它,你能用其他属性吗? - ChrisF