在网格中的文本框中调整字体大小 [英] Resize font in TextBox in Grid
问题描述
我的以下问题得到了回答,但我刚刚意识到,现在FontSize
仅在一个方向上调整大小.
My question below is answered but I just realised that now the FontSize
only resizes in one direction.
是否可以绑定两条路径?还是其他选择?
Is there a possibility to bind two paths? Or another option?
上一个问题
我有一个Grid
[20,20],其中包含TextBox
es.在这些TextBoxe
中,我输入数字.当应用程序启动时,它是全屏的.如果我调整窗口的大小,则带有TexBox
es的Grid
也会重新调整大小.但是Font
保持不变.所以我想在调整窗口大小时更改FontSize
.我试过了:
Previous question
I have a Grid
[20,20] with TextBox
es in it. In these TextBoxe
s I put numbers. When the application starts up it's fullscreen. If I resize the window the Grid
with the TexBox
es also resizes. But the Font
stays the same. So I want to change the FontSize
when the Window resizes. I tried:
FontSize="{Binding ElementName=aTextBox, Path=Height}"
.但这是行不通的.用属性 between the The 请注意,由于 Notice that I used a converter because the ratio 这篇关于在网格中的文本框中调整字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!Height
或Width
绑定Grid
或Window
也不起作用.绑定到滑块后,FontSize
会根据滑块的值而变化.有人有很好的解决方案吗? TextBox
tags. But that doesn't work. A binding with the Grid
or Window
with property Height
or Width
didn't work either. With binding to a slider the FontSize
changes according to the the value of the slider. Does anybody have a nice solution? 推荐答案
Height
属性是TextBox
的初始高度. ActualHeight
表示TextBox
在屏幕上绘制时的高度.这样您的绑定就变成:Height
property is the initial height of the TextBox
. The ActualHeight
represents the height of the TextBox
as it is drawn on the screen. So your binding becomes:<TextBox FontSize="{Binding Path=ActualHeight, RelativeSource={RelativeSource Self}, Converter={StaticResource HeightToFontSizeConverter}}" Text="12345" />
Height
与FontSize
之比不是1:1,并且文本对于TextBox
而言太大,所以我使用了转换器:Height
to FontSize
is not 1:1 and the text is too big for the TextBox
:class HeightToFontSizeConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
var height = (double) value;
return .65 * height;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
}