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.
但我看到标签贴在图像上。
Also is there any way to have some parameter like cell padding (from right/left/top/bottom)?
还有什么方法可以有一些参数,比如单元格填充(从右/左/上/下)?
2 个解决方案
#1
4
try using Grid
instead of StackPanel
尝试使用网格而不是StackPanel。
<Grid>
<Image ... HorizontalAlignment="Left"/>
<Label ... HorizontalAlignment="Right"/>
</Grid>
there is Padding
property which is published by types like Block
, Border
, Control
, and TextBlock
so for example it will not be published by Image
control, which inherits directly from FrameworkElement
, but will be by Label
which is a Control
有一些填充属性是由块、边框、控件和TextBlock等类型发布的,例如,它不会由图像控件发布,图像控件直接继承自FrameworkElement,而是由控件的Label发布
#2
8
Try using a DockPanel
instead
尝试使用DockPanel
<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?
对于填充问题,您要填充哪个元素?
#1
4
try using Grid
instead of StackPanel
尝试使用网格而不是StackPanel。
<Grid>
<Image ... HorizontalAlignment="Left"/>
<Label ... HorizontalAlignment="Right"/>
</Grid>
there is Padding
property which is published by types like Block
, Border
, Control
, and TextBlock
so for example it will not be published by Image
control, which inherits directly from FrameworkElement
, but will be by Label
which is a Control
有一些填充属性是由块、边框、控件和TextBlock等类型发布的,例如,它不会由图像控件发布,图像控件直接继承自FrameworkElement,而是由控件的Label发布
#2
8
Try using a DockPanel
instead
尝试使用DockPanel
<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?
对于填充问题,您要填充哪个元素?