在wpf用户控件中,我正在创建最终用户,可以选择更改所包含图像的默认大小。当最初设计控件时,我根据试验和错误确定了最终的边距大小,最终确定了对我来说正确的内容。
当图像尺寸为16 x 16或24 x 24时,整体外观合理;
但是一旦你开始大幅增加图像大小为两个文本框,控件中的文本块就会与图像失去同步。
我最初用于文本和文本块的xaml如下所示(它还包括中间的查找按钮,但有助于显示所有按钮的定义)。
<TextBox x:Name="Record" BorderThickness="0" Margin="6" ></TextBox>
<Button Background="#00000000" x:Name="Find" Height="Auto" Width="Auto"
ToolTip="Find the Record at this position." BorderThickness="0">
<StackPanel Margin="2" Orientation="Horizontal">
<Image Source="{Binding ImageFind, ElementName=DN}"
Width="{Binding ImageFindWidth, ElementName=DN}"
Height="{Binding ImageFindHeight, ElementName=DN}"/>
<TextBlock Margin="3" Text="{Binding TextFind,ElementName=DN}"/>
</StackPanel>
</Button>
<TextBlock Margin="6">of</TextBlock>
<TextBox x:Name="Records" BorderThickness="0"
Margin="6"
Text="{Binding RecordsCount, ElementName=DN}"></TextBox>
所有按钮和文本框都包含在水平方向设置的堆栈面板中。
我想知道的是,在最终用户更改图像的宽度高度时,我可以应用于文本框和文本块的数学公式(它们在任一维度中始终相同)这将纠正布局,从而使文本与图像的中间对齐。
可能还有一些其他的wpf布局技巧我尚未学习做这种事情,无论哪种方式我欢迎提出建议。
由于
答案 0 :(得分:1)
在VerticalAlignment
上设置TextBlock
属性,在VerticalContentAlignment
设置TextBox
。
<TextBlock Margin="6" VerticalAlignment='Center'>of</TextBlock>