[英]WPF: how to alignment 2 labels in different sizes
I have simple Grid
with 2 label, one of them get its value (0-100) from Slider Value
and i want this 2 labels
show me the Slider Value
in this format: 我有带有2个标签的简单
Grid
,其中之一从Slider Value
获取其值(0-100),我希望这2个labels
以以下格式向我显示Slider Value
:
x Value - the value need to be in different size and much bigger then the 'x' char, So this is my start position: x值-值必须具有不同的大小并且比'x'字符大得多,所以这是我的开始位置:
And while the Value
changed things become ugly: 当
Value
改变时,事情变得丑陋:
My code: 我的代码:
<Grid Margin="857,112,87,383" >
<Label Content="{Binding ElementName=knobSlider, Path=Value, UpdateSourceTrigger=PropertyChanged}"
Foreground="#FFB2B2B2" VerticalAlignment="Center" HorizontalAlignment="Center"
FontFamily="Buxton Sketch" FontSize="40" Grid.Column="1" Padding="0,0,0,0"/>
<Label Content="x" FontSize="20" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Column="1" Foreground="#FFB2B2B2" Padding="0,20,0,0"/>
</Grid>
Any idea how to fix it ? 知道如何解决吗?
BTW: i want my value will show with only 1 decimal number after the point. 顺便说一句:我希望我的值在该点之后仅显示1个十进制数字。
You can add a string format to the Label that should give you all the control over the number you need. 您可以向标签添加字符串格式,该格式应使您可以对所需编号进行所有控制。
For example: 例如:
<Label Content="{Binding ElementName=knobSlider, Path=Value, UpdateSourceTrigger=PropertyChanged}" ContentStringFormat="N1" />
An alternative is to add the string format directly to the binding. 另一种选择是将字符串格式直接添加到绑定中。 That works too.
那也行。 Just like that:
就像这样:
<Label Content="{Binding ElementName=knobSlider, Path=Value, UpdateSourceTrigger=PropertyChanged, StringFormat=N2}" />
For your second problem the design of your grid is the problem. 对于第二个问题,网格的设计就是问题。 Grid allows you to create columns and rows.
网格允许您创建列和行。 Make use of it!
利用它! Like so:
像这样:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="x" Padding="0,20,0,0" />
<Label Grid.Column="1" Content="{Binding ElementName=knobSlider, Path=Value, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
Now both labels are in their own column and can't overlap. 现在,两个标签都在各自的列中,并且不能重叠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.