xamarin 我想更改单选按钮的形状,可以更改边框大小吗?

pu82cl6c  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(134)
<ContentPage.Resources>
        <ControlTemplate x:Key="FrameRadioTemplate">
            <Frame
                Padding="10"
                BackgroundColor="{DynamicResource ColorBorder000}"
                BorderColor="Red"
                HeightRequest="50"
                WidthRequest="130">
                <ContentPresenter>
                    <ContentPresenter.Resources>
                        <Style TargetType="Label">
                            <Setter Property="HorizontalOptions" Value="Center" />
                            <Setter Property="VerticalOptions" Value="Center" />

                            <Style.Triggers>
                                <DataTrigger
                                    Binding="{Binding Path=IsChecked, Source={x:RelativeSource AncestorType={x:Type RadioButton}}}"
                                    TargetType="Label"
                                    Value="True">
                                    <Setter Property="TextColor" Value="{DynamicResource ColorText111}" />
                                    <Setter Property="FontAttributes" Value="Bold" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ContentPresenter.Resources>
                </ContentPresenter>

                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CheckedStates">
                        <VisualState x:Name="Checked">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor" Value="{DynamicResource ColorBack004}" />
                            </VisualState.Setters>
                        </VisualState>

                        <VisualState x:Name="Unchecked">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor" Value="{DynamicResource ColorBack000}" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
            </Frame>
        </ControlTemplate>
    </ContentPage.Resources>


<StackLayout
                                            x:Name="xDispContents"
                                            Grid.Row="9"
                                            Grid.Column="1"
                                            HorizontalOptions="StartAndExpand"
                                            Orientation="Horizontal"
                                            Spacing="0">

                                            <Ctrl:CtrlRadioButton
                                                x:Name="xBtnDisp_ABS"
                                                ControlTemplate="{StaticResource FrameRadioTemplate}"
                                                HorizontalOptions="Center"
                                                VerticalOptions="Center">

                                                <Ctrl:CtrlRadioButton.Content>
                                                    <!--<Label TextColor="{DynamicResource ColorText000}" />-->
                                                    <Ctrl:CtrlButton Text="ABS" />
                                                </Ctrl:CtrlRadioButton.Content>
                                            </Ctrl:CtrlRadioButton>

                                            <Ctrl:CtrlRadioButton
                                                x:Name="xBtnDisp_Trans"
                                                ControlTemplate="{StaticResource FrameRadioTemplate}"
                                                HorizontalOptions="Center"
                                                VerticalOptions="Center">

                                                <Ctrl:CtrlRadioButton.Content>
                                                    <Label Text="%T" TextColor="{DynamicResource ColorText000}" />
                                                </Ctrl:CtrlRadioButton.Content>
                                            </Ctrl:CtrlRadioButton>

                                        </StackLayout>

I want to change the shape of the radio button, can I change the border size?
I'm trying to change the shape of a radio button's appearance using a control template. But I want to change the border thickness of the frame, but there is no way.
The default thickness is too thick. I've looked for many other examples, but there's no information about the thickness, so I'm asking.

klsxnrf1

klsxnrf11#

也许你可以用这个,框架中的框架。改变“带边框”颜色的填充。

<Frame  HeightRequest="50" WidthRequest="100" BackgroundColor="Red" HorizontalOptions="Center" VerticalOptions="Start" Padding="0.7" IsClippedToBounds="True">
        <Frame  HeightRequest="50" WidthRequest="100" BackgroundColor="White" HorizontalOptions="Center" VerticalOptions="Start" Margin="0" Padding="0" IsClippedToBounds="True">
            <Label Text="Padding 0.7" HorizontalOptions="Center" />
        </Frame>
    </Frame>

    <Frame  HeightRequest="50" WidthRequest="100" BackgroundColor="Red" HorizontalOptions="Center" VerticalOptions="Start" Padding="1" IsClippedToBounds="True">
        <Frame  HeightRequest="50" WidthRequest="100" BackgroundColor="White" HorizontalOptions="Center" VerticalOptions="Start" Margin="0" Padding="0" IsClippedToBounds="True">
            <Label Text="Padding 1" HorizontalOptions="Center" />
        </Frame>
    </Frame>
    
    <Frame  HeightRequest="50" WidthRequest="100" BackgroundColor="Red" HorizontalOptions="Center" VerticalOptions="Start" Padding="5" IsClippedToBounds="True">
        <Frame  HeightRequest="50" WidthRequest="100" BackgroundColor="White" HorizontalOptions="Center" VerticalOptions="Start" Margin="0" Padding="0" IsClippedToBounds="True">
            <Label Text="Padding 5" HorizontalOptions="Center" />
        </Frame>
    </Frame>

结果在不同大小的红色边框。

相关问题