我想創建像預期輸出一樣的單選按鈕組(我在鏈接中添加)。我在下面添加了一張照片。請幫我解決我的錯誤
<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]
這是我的expexted輸出****, 但我的輸出是這個
uj5u.com熱心網友回復:
使用 WPF 進行設計時,您應該始終使用布局容器來排列控制元件,這與您過去在螢屏上拖放控制元件的 WindowsForms 方式不同。一開始它有點復雜,但很快就會得到回報,因為你的窗戶會變得動態。
寬度現在在布局容器中定義,因此如果您以后需要更改它,您只需在父級上更改它。
<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>
您現在可以定位堆疊面板一次,所有按鈕都將跟隨
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/408086.html
標籤:
