按钮中的 WPF 图像和文本对齐方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18226341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF image and text alignment in button
提问by Babak.Abad
I need a way to align a label to right and align an image to right. I tried this code:
我需要一种将标签向右对齐并将图像向右对齐的方法。我试过这个代码:
<Button HorizontalAlignment="Left" Margin="11,265,0,0" VerticalAlignment="Top" Width="190" Height="51">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<Image Source="Resources/Accept-icon.png" Stretch="Uniform" HorizontalAlignment="Left"/>
<Label Content="?????" HorizontalContentAlignment="Right" VerticalAlignment="Center" FontFamily="2 badr" FontSize="20"/>
</StackPanel>
</Button>
But I see label sticks to image.
但我看到标签贴在图像上。
Alsois there any way to have some parameter like cell padding (from right/left/top/bottom)?
也有没有什么办法能有像单元格填充了一些参数(由左/右/上/下)?
回答by Dutts
Try using a DockPanelinstead
尝试使用 aDockPanel代替
<Button HorizontalAlignment="Left" Margin="11,265,0,0" VerticalAlignment="Top" Width="190" Height="51">
<DockPanel HorizontalAlignment="Stretch">
<Image Source="Resources/Accept-icon.png" Stretch="Uniform" DockPanel.Dock="Left"/>
<Label Content="?????" DockPanel.Dock="Right" VerticalAlignment="Center" FontFamily="2 badr" FontSize="20"/>
</DockPanel>
</Button>
For your padding question, which element are you trying to pad?
对于您的填充问题,您要填充哪个元素?
回答by dkozl
try using Gridinstead of StackPanel
尝试使用Grid代替StackPanel
<Grid>
<Image ... HorizontalAlignment="Left"/>
<Label ... HorizontalAlignment="Right"/>
</Grid>
there is Paddingproperty which is published by types like Block, Border, Control, and TextBlockso for example it will not be published by Imagecontrol, which inherits directly from FrameworkElement, but will be by Labelwhich is a Control
有Padding其通过类型出版喜欢属性Block,Border,Control,和TextBlock因此,例如它不会被发表Image控制,直接它继承自FrameworkElement,但将通过Label这是一个Control

