編輯有問題的新照片。
如果你不介意額外的輸入,你可以使用這個:
<Style TargetType="RadioButton" x:Key="rb">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<Grid>
<RadioButton IsChecked="{Binding Path=IsChecked, RelativeSource={RelativeSource Mode=TemplatedParent}}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Border Background="Transparent" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
可正常工作在我的小測試程序:
<Grid>
<Grid.Resources>
<Style TargetType="RadioButton" x:Key="rb">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<Grid>
<RadioButton IsChecked="{Binding Path=IsChecked, RelativeSource={RelativeSource Mode=TemplatedParent}}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Border Background="Transparent" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ListBoxItem" x:Key="ics">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<RadioButton HorizontalAlignment="Center" VerticalAlignment="Center" />
<RadioButton HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="1" />
<RadioButton Style="{StaticResource rb}" Grid.Column="2" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<ListBox ItemContainerStyle="{StaticResource ics}">
<ListBoxItem>1</ListBoxItem>
</ListBox>
</Grid>
它看起來像:
![enter image description here](https://i.stack.imgur.com/dH4KI.png)
(顯然你會想要使用提供的第三種方法)
我知道這看起來不多,但它會給你你的結果。再次,請原諒額外的打字和缺乏使用的編碼標準。
爲此,鼠標懸停不會給視覺效果,但命中測試是有效的。我認爲只要這是在平板電腦上,並且不跟蹤手指,就可以。
如果你只是想控制,以更大的尺寸,你可以使用以下方法
您可以通過RenderTransform
屬性設置爲ScaleTransform
對象調整控制。
:
調整所有RadioButton
容器(窗口,網頁,電網等)
<Window.Resources>
<Style TargetType="RadioButton">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="10" ScaleY="10"/>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
或全部關鍵
<Style TargetType="RadioButton" x:Key="resizeRadioButton">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="10" ScaleY="10"/>
</Setter.Value>
</Setter>
</Style>
使用中的對象
<RadioButton Style="{StaticResource resizeRadioButton}" />
或單獨
<RadioButton>
<RadioButton.RenderTransform>
<ScaleTransform ScaleX="10" ScaleY="10"/>
</RadioButton.RenderTransform>
</RadioButton>
然而,如果你要使用更大的控制和更大的點擊區域(或一組類型的所有控件只是更大的點擊區域)的組合,可以使用方法:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="RadioButton">
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.5" ScaleY="1.5"/>
</Setter.Value>
</Setter>
<Setter Property="Content">
<Setter.Value>
<Border>
<Rectangle Margin="-10" Fill="Transparent" />
</Border
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
或者只是使用另一個容器內的控件的默認行爲,並使用HorizontalAlignment="Stretch"
道具不過,這會讓我相信左上角的控制權。
您是否嘗試過拉伸特性?您是否嘗試過在單選按鈕本身設置屬性,如內容對齊?您的網格是否在任何一種面板內(因爲這會拉伸)?你嘗試過邊框而不是標籤嗎? –
嗨Merlyn,是的,我試過拉伸屬性,我已經嘗試了單選按鈕本身的所有可能屬性(包括內容對齊)。網格直接在我的用戶控制之下(該用戶控件隨後被添加到項目面板,但這確實不成問題?)。邊框不允許內容對齊,這會在左上角留下單選按鈕。 –
現在你已經獲得了屏幕截圖的問題+1。這使得它更清楚你在找什麼。 –