【发布时间】:2016-01-21 16:40:49
【问题描述】:
这是我的代码:
<StackPanel Name="stackPanelMain" Orientation="Vertical">
<RadioButton Content="Work" Style="{StaticResource Rick_RadioButtonOption}"/>
<RadioButton Content="Non-Work" Style="{StaticResource Rick_RadioButtonOption}"/>
</StackPanel>
风格如下:
<Style TargetType="RadioButton" x:Key="Rick_RadioButtonOption">
<Setter Property="Background" Value="White" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Margin" Value="5" />
<Setter Property="FontSize" Value="18" />
<Setter Property="Padding" Value="27" />
</Style>
我增加了填充,因此更明显的是发生了什么。文本按预期/要求居中,但实际单选按钮仍位于左上角:
如何使单选按钮垂直居中并略微向右?我尝试了here 的解决方案,但它不适用于我的情况。
编辑 根据@asitis 的要求 - 如果我在样式中设置这两个属性,这就是我得到的:
<Setter Property="Background" Value="Red" />
<Setter Property="Foreground" Value="Red" />
【问题讨论】:
-
我尝试了你的风格和 xaml。按预期工作。但是如何使用上面的 xaml 获得这个高度?
-
@asitis 我是 xaml 的新手。使用填充设置元素的高度。你是这个意思吗?我不需要特定的高度。文本/单选按钮周围只有一点间距
-
我使用了相同的 xaml & 样式。我得到了正确对齐的项目。但高度适合单选按钮
-
你能分享产生图像中设计的确切代码吗?
-
以上几乎是该页面的所有代码——只是缺少标准的
Page标签