分组单选按钮
Grouping Radio button
我想像预期的输出一样创建单选按钮组(我在 link 中添加)。我在下面添加了一张照片。请帮我解决我的错误
<Page.Resources>
<Style x:Key="GroupToggleStyle" TargetType="RadioButton" BasedOn="{StaticResource {x:Type ToggleButton}}">
<Setter Property="Foreground" Value="Blue"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource Self}}"
Value="True">
<DataTrigger.Setters>
<Setter Property="Foreground" Value="Red"/>
</DataTrigger.Setters>
</DataTrigger>
</Style.Triggers>
</Style>
</Page.Resources>
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}"
CommandParameter="English" Content="English" Width="80"
Style="{StaticResource GroupToggleStyle}" Margin="8,15,162,21" FontSize="30" Grid.Column="3" Grid.Row="3" BorderBrush="#FF860707"/>
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}"
CommandParameter="Sinhala" Content="Sinhala" Width="80"
Style="{StaticResource GroupToggleStyle}" Margin="78,19,77,21" FontSize="30" Grid.Column="3" Grid.Row="3"/>
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}"
CommandParameter="Tamil" Content="தமிழ்" Width="80"
Style="{StaticResource GroupToggleStyle}" Margin="165,10,10,21" FontSize="30" Grid.Column="3" Grid.Row="3"/>[enter image description here][1]
this is my expexted output****
but my output is this
在使用 WPF 进行设计时,您应该始终使用布局容器来排列控件,这与您仅用于在屏幕上拖放控件的 WindowsForms 方式不同。
一开始有点复杂,但很快就会得到回报,因为你的 windows 变得动态了。
宽度现在在布局容器中定义,因此如果您以后需要更改它,您只需在父级上更改它。
<StackPanel Width="80">
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}" CommandParameter="English" Content="English" Style="{StaticResource GroupToggleStyle}" FontSize="30" Grid.Column="3" Grid.Row="3" BorderBrush="#FF860707"/>
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}" CommandParameter="Sinhala" Content="Sinhala" Width="80" Style="{StaticResource GroupToggleStyle}" FontSize="30" Grid.Column="3" Grid.Row="3"/>
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}" CommandParameter="Tamil" Content="தமிழ்" Width="80" Style="{StaticResource GroupToggleStyle}" FontSize="30" Grid.Column="3" Grid.Row="3"/>
</StackPanel>
您现在可以定位堆栈面板一次,所有按钮都会跟随
我想像预期的输出一样创建单选按钮组(我在 link 中添加)。我在下面添加了一张照片。请帮我解决我的错误
<Page.Resources>
<Style x:Key="GroupToggleStyle" TargetType="RadioButton" BasedOn="{StaticResource {x:Type ToggleButton}}">
<Setter Property="Foreground" Value="Blue"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource Self}}"
Value="True">
<DataTrigger.Setters>
<Setter Property="Foreground" Value="Red"/>
</DataTrigger.Setters>
</DataTrigger>
</Style.Triggers>
</Style>
</Page.Resources>
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}"
CommandParameter="English" Content="English" Width="80"
Style="{StaticResource GroupToggleStyle}" Margin="8,15,162,21" FontSize="30" Grid.Column="3" Grid.Row="3" BorderBrush="#FF860707"/>
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}"
CommandParameter="Sinhala" Content="Sinhala" Width="80"
Style="{StaticResource GroupToggleStyle}" Margin="78,19,77,21" FontSize="30" Grid.Column="3" Grid.Row="3"/>
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}"
CommandParameter="Tamil" Content="தமிழ்" Width="80"
Style="{StaticResource GroupToggleStyle}" Margin="165,10,10,21" FontSize="30" Grid.Column="3" Grid.Row="3"/>[enter image description here][1]
this is my expexted output**** but my output is this
在使用 WPF 进行设计时,您应该始终使用布局容器来排列控件,这与您仅用于在屏幕上拖放控件的 WindowsForms 方式不同。 一开始有点复杂,但很快就会得到回报,因为你的 windows 变得动态了。
宽度现在在布局容器中定义,因此如果您以后需要更改它,您只需在父级上更改它。
<StackPanel Width="80">
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}" CommandParameter="English" Content="English" Style="{StaticResource GroupToggleStyle}" FontSize="30" Grid.Column="3" Grid.Row="3" BorderBrush="#FF860707"/>
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}" CommandParameter="Sinhala" Content="Sinhala" Width="80" Style="{StaticResource GroupToggleStyle}" FontSize="30" Grid.Column="3" Grid.Row="3"/>
<RadioButton GroupName="LanguageGroup" Command="{Binding LanguageChangeCommand}" CommandParameter="Tamil" Content="தமிழ்" Width="80" Style="{StaticResource GroupToggleStyle}" FontSize="30" Grid.Column="3" Grid.Row="3"/>
</StackPanel>
您现在可以定位堆栈面板一次,所有按钮都会跟随