2

我创建了一个简单的单选按钮样式,如下所示:

<Style TargetType="RadioButton" >
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ToggleButton">
                <Border x:Name="BORDER_PART" BorderBrush="Gray" CornerRadius="5,5,0,0" BorderThickness="0.5" >
                    <TextBlock x:Name="LABEL_PART" HorizontalAlignment="Center" FontFamily="Calibri" FontSize="14" VerticalAlignment="Center" Text="{TemplateBinding Content}" />
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="True">
                        <Setter TargetName="BORDER_PART" Property="Background" Value="White"/>
                        <Setter TargetName="BORDER_PART" Property="BorderThickness" Value="0.5 0.5 0.5 0"/>
                        <Setter TargetName="LABEL_PART" Property="FontWeight" Value="Bold"/>
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="LABEL_PART" Property="FontWeight" Value="Bold"/>
                        <Setter TargetName="BORDER_PART" Property="BorderBrush" Value="Black"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

然后我将它应用到这样的网格中:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <RadioButton Grid.Column="0" GroupName="TabNavigator" IsChecked="True" Content="Home" />
    <RadioButton Grid.Column="1" GroupName="TabNavigator" Content="Dashboard"/>

    <TextBlock x:Name="moveAroundTextBlock" Text="some text" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0 0 0 5"/>

    <Button Content="Help" Grid.Column="3" />
    <Button Content="Close" Grid.Column="4" />
</Grid>

正如您在样式中看到的,当单选按钮被鼠标悬停时,文本将变为粗体,这一切都很好,但是当它应用在像上面这样的网格中时,“moveAroundTextBlock”看起来就像每次单选按钮切换时都会移动在粗体和常规之间,因为单选按钮所在的列被标记为自动(这是一个要求,尽管由于可能本地化为其他语言,所以文本不会被截断)

所以问题是:
如何使“moveAroundTextBlock”保持在其位置,但有以下限制:
- 单选按钮和按钮的列必须是自动
的 - moveAroundTextBlock 必须在其列中水平居中

(或者换句话说,如何使raidobuttons的列在内容为粗体时不会变宽,同时保留自动调整大小的列)

4

0 回答 0