IntegerUpDown控件自定义样式

本文详细介绍了如何优化水印文本框和按钮的样式,包括调整垂直和水平对齐方式,以及修改背景颜色和边框厚度,旨在提高用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<Style TargetType="{x:Type xctk:IntegerUpDown}">
            <Style.Resources>
                <Style TargetType="{x:Type xctk:WatermarkTextBox}"
               BasedOn="{StaticResource {x:Type xctk:WatermarkTextBox}}">
                    <Setter Property="VerticalAlignment" Value="Stretch"/>
                    <Setter Property="HorizontalAlignment" Value="Stretch"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate  TargetType="{x:Type xctk:WatermarkTextBox}">
                                <Border x:Name="Border" BorderThickness="0,0,1,0" MinHeight="20"  BorderBrush="{TemplateBinding BorderBrush}" Background="#434245" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="Stretch">
                                    <Grid>
                                        <ScrollViewer x:Name="PART_ContentHost" Style="{DynamicResource ScorllStyle}"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                        <ContentPresenter x:Name="PART_WatermarkHost" Content="{TemplateBinding Watermark}" ContentTemplate="{TemplateBinding WatermarkTemplate}"
                              VerticalAlignment="Center" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              IsHitTestVisible="False" Visibility="Collapsed" />
                                    </Grid>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <!--上下箭头Style-->
                <Style TargetType="{x:Type xctk:ButtonSpinner}">
                    <Setter Property="VerticalAlignment" Value="Center"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type xctk:ButtonSpinner}">
                                <Border x:Name="Border" BorderBrush="White" BorderThickness="1" Background="red" SnapsToDevicePixels="True">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <ContentPresenter Content="{TemplateBinding Content}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                        <Grid Grid.Column="1" Width="19">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="*"/>
                                                <RowDefinition Height="*"/>
                                            </Grid.RowDefinitions>
                                            <RepeatButton  x:Name="PART_IncreaseButton" IsTabStop="{TemplateBinding IsTabStop}">
                                            	 <RepeatButton.ContentTemplate>
                                                    <DataTemplate>
                                                        <Path Data="M0,3C0,3 0,4 0,4 0,4 3,4 3,4 3,4 3,3 3,3 3,3 4,3 4,3 4,3 4,4 4,4 4,4 7,4 7,4 7,4 7,3 7,3 7,3 6,3 6,3 6,3 6,2 6,2 6,2 5,2 5,2 5,2 5,1 5,1 5,1 4,1 4,1 4,1 4,0 4,0 4,0 3,0 3,0 3,0 3,1 3,1 3,1 2,1 2,1 2,1 2,2 2,2 2,2 1,2 1,2 1,2 1,3 1,3 1,3 0,3 0,3z" Focusable="False" Fill="White" HorizontalAlignment="Center" SnapsToDevicePixels="True" VerticalAlignment="Center"/>
                                                    </DataTemplate>

                                                </RepeatButton.ContentTemplate>
                                               
                                            </RepeatButton>
                                            <RepeatButton x:Name="PART_DecreaseButton" IsTabStop="{TemplateBinding IsTabStop}" Grid.Row="1" >
                                            	 <RepeatButton.ContentTemplate>
                                                    <DataTemplate>
                                                        <Path Data="M0,1C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1z" Focusable="False" Fill="White" HorizontalAlignment="Center" Height="4" SnapsToDevicePixels="True" VerticalAlignment="Center" Width="7"/>
                                                    </DataTemplate>
                                                </RepeatButton.ContentTemplate>
                                            </RepeatButton>
                                        </Grid>
                                    </Grid>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsEnabled" SourceName="PART_IncreaseButton" Value="False">
                                        <!--BorderBrush="#353535"  BorderThickness="0.1" Background="Transparent"-->
                                        <Setter Property="Background" Value="gray"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Style.Resources>
            <Setter Property="Margin" Value="2"/>
            <Setter Property="VerticalAlignment" Value="Stretch"/>
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Padding" Value="0"/>
        </Style>
		

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值