[英]How to put text on top in RadioButton
I'm trying to achieve effect shown in attached file but without success. 我正在尝试实现附加文件中显示的效果,但没有成功。 It is even possible? 甚至可能吗? I was trying to put textbox inside the radiobutton and set to it horizontal and vertical content aligment but it's not working as I want. 我试图将文本框放在radiobutton中并设置为水平和垂直内容对齐,但它不能按我的意愿工作。 Any advices are welcome. 欢迎任何建议。
Resource 资源
<Window.Resources>
<Style x:Key="RadioButton" TargetType="RadioButton">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<StackPanel>
<TextBlock FontFamily="Segoe Ui Dark" HorizontalAlignment="Center" Foreground="Black" Text="{TemplateBinding Content}" FontSize="12" FontWeight="SemiBold" Margin="0,0,0,2" />
<BulletDecorator Grid.Column="0" Background="Transparent" >
<BulletDecorator.Bullet>
<Grid Width="14" Height="14" >
<Ellipse x:Name="Border" Fill="Transparent" StrokeThickness="1" Stroke="Black" />
<Ellipse x:Name="CheckMark" Margin="4" Fill="Black"/>
</Grid>
</BulletDecorator.Bullet>
</BulletDecorator>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="false">
<Setter TargetName="CheckMark" Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="Border" Property="Fill" Value="LightGray" />
<Setter TargetName="Border" Property="Stroke" Value="Black" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Border" Property="Fill" Value="White" />
<Setter TargetName="Border" Property="Stroke" Value="Black" />
<Setter TargetName="Border" Property="StrokeThickness" Value="4" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
Xaml XAML
<StackPanel Orientation="Horizontal">
<RadioButton Content="1" Style="{StaticResource RadioButton}" Margin="5"></RadioButton>
<RadioButton Content="2" Style="{StaticResource RadioButton}" Margin="5"></RadioButton>
<RadioButton Content="3" Style="{StaticResource RadioButton}" Margin="5"></RadioButton>
<RadioButton Content="4" Style="{StaticResource RadioButton}" Margin="5" ></RadioButton>
<RadioButton Content="5" Style="{StaticResource RadioButton}" Margin="5"></RadioButton>
</StackPanel>
Result 结果
Depending on your .Net version download the template from http://msdn.microsoft.com/en-us/library/ms751600(v=vs.90).aspx . 根据您的.Net版本,从http://msdn.microsoft.com/en-us/library/ms751600(v=vs.90).aspx下载该模板。
Now change them according to your requirements. 现在根据您的要求进行更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.