Wpf按钮,输入框,下拉框美化

`

<ControlTemplate x:Key="CustomProgressBarTemplate" TargetType="ProgressBar">
    <Grid>
        <Border x:Name="PART_Track" CornerRadius="2" BorderBrush="#AAAAAA" BorderThickness="1">
            <Border.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                    <GradientStop Color="#EEEEEE" Offset="0"/>
                    <GradientStop Color="#CCCCCC" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <Rectangle x:Name="PART_Indicator" HorizontalAlignment="Left" Fill="#248735"/>
        </Border>
    </Grid>
    <ControlTemplate.Triggers>
        <Trigger Property="IsIndeterminate" Value="True">
            <!-- 处理不确定模式的逻辑 -->
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

<Style x:Key="ToggleButtonStyle" TargetType="{x:Type ToggleButton}">
    <Setter Property="Width" Value="50"></Setter>
    <Setter Property="Height" Value="20"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ToggleButton">
                <!--定义视觉树-->
                <Border x:Name="border" BorderThickness="1.5" CornerRadius="9" BorderBrush="#aaa" Background="#2790ff">
                    <Grid x:Name="togglebutton" HorizontalAlignment="Right">
                        <Border Width="17" Height="17" CornerRadius="9" Background="White"/>
                    </Grid>
                    <!--阴影设置-->
                    <Border.Effect>
                        <DropShadowEffect Color="Gray" BlurRadius="5" ShadowDepth="0" Opacity="0.5" />
                    </Border.Effect>
                </Border>
                <!--定义触发器-->
                <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="false">
                        <Setter TargetName="border" Property="Background" Value="#ccc"/>
                        <Setter TargetName="togglebutton" Property="HorizontalAlignment" Value="Left"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<!--<c:CheckConverter x:Key="CheckConverter"/>-->
<Style x:Key="pro1" TargetType="{x:Type ProgressBar}">
    <Setter Property="Height" Value="15"/>
    <Setter Property="Background" Value="#F9F9F9"/>
    <Setter Property="Padding" Value="5,2"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ProgressBar}">
                <Border Padding="0" CornerRadius="10" Background="{TemplateBinding Background}">
                    <Grid Height="{TemplateBinding Height}">
                        <Border x:Name="PART_Track"/>
                        <Grid  x:Name="PART_Indicator" Background="Transparent" 
                                   HorizontalAlignment="Left" >
                            <Border Background="Green" CornerRadius="10">
                                <Viewbox HorizontalAlignment="Right"
                                             Margin="{TemplateBinding Padding}" 
                                             SnapsToDevicePixels="True">
                                    <TextBlock Foreground="White"
                                                HorizontalAlignment="Right"
                                                Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Value,StringFormat={}{0}%}"/>
                                </Viewbox>
                            </Border>
                        </Grid>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Background" Value="gray"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style x:Key="TextBoxStyle" TargetType="TextBox">
    <Setter Property="Foreground" Value="Black"/>
    <Setter Property="BorderBrush" Value="#FF3C3C3C"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="Padding" Value="5"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="TextBox">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        CornerRadius="5">
                    <ScrollViewer x:Name="PART_ContentHost"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <!-- 当 IsReadOnly 为 true 时,改变背景色 -->
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Background" Value="LightGray"/>
            <Setter Property="Foreground" Value="DarkGray"/>
            <Setter Property="BorderBrush" Value="Gray"/>
        </Trigger>
    </Style.Triggers>
</Style>

<Style x:Key="ButtonStyle" TargetType="Button">
    <Setter Property="FontSize" Value="16"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="Margin" Value="10"/>
    <Setter Property="Foreground" Value="White"/>
    <Setter Property="Background" Value="Green"/>
    <Setter Property="Padding" Value="10,5"/>
    <Setter Property="FontWeight" Value="Bold"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" CornerRadius="10">
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Background" Value="LightGray"/>
            <Setter Property="Foreground" Value="DarkGray"/>
            <Setter Property="BorderBrush" Value="Gray"/>
        </Trigger>
    </Style.Triggers>
</Style>

<!-- 定义 ComboBox 的样式 -->
<Style x:Key="ComboBoxStyle" TargetType="ComboBox">
    <!-- 默认样式 -->
    <Setter Property="Background" Value="White"/>
    <Setter Property="Foreground" Value="#FF1E1E1E"/>
    <Setter Property="BorderBrush" Value="#FF3C3C3C"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="Padding" Value="5"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ComboBox">
                <Grid>
                    <Border x:Name="Border" Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="5"/>
                    <ToggleButton x:Name="ToggleButton"
                                      Grid.Column="1"
                                      Focusable="False"
                                      IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                      ClickMode="Press">
                        <ToggleButton.Template>
                            <ControlTemplate TargetType="ToggleButton">
                                <Border Background="Transparent">
                                    <Path x:Name="Arrow"
                                              Fill="Green"
                                              HorizontalAlignment="Right"
                                              VerticalAlignment="Center"
                                              Data="M 0 0 L 4 4 L 8 0 Z"/>
                                </Border>
                            </ControlTemplate>
                        </ToggleButton.Template>
                    </ToggleButton>
                    <ContentPresenter x:Name="ContentSite"
                                          IsHitTestVisible="False"
                                          Content="{TemplateBinding SelectionBoxItem}"
                                          ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                                          ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                          Margin="5,0,0,0"
                                          VerticalAlignment="Center"
                                          HorizontalAlignment="Left"/>
                    <TextBox x:Name="PART_EditableTextBox"
                                 Style="{x:Null}"
                                 HorizontalAlignment="Left"
                                 VerticalAlignment="Center"
                                 Margin="5,0,0,0"
                                 Focusable="True"
                                 Background="Transparent"
                                 Foreground="{TemplateBinding Foreground}"
                                 Visibility="Hidden"
                                 IsReadOnly="{TemplateBinding IsReadOnly}"/>
                    <Popup x:Name="Popup"
                               Placement="Bottom"
                               IsOpen="{TemplateBinding IsDropDownOpen}"
                               AllowsTransparency="True"
                               Focusable="False"
                               PopupAnimation="Slide">
                        <Grid x:Name="DropDown"
                                  SnapsToDevicePixels="True"
                                  MinWidth="{TemplateBinding ActualWidth}"
                                  MaxHeight="{TemplateBinding MaxDropDownHeight}">
                            <Border x:Name="DropDownBorder"
                                        Background="{TemplateBinding Background}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        BorderThickness="1"
                                        CornerRadius="5"/>
                            <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
                                <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained"/>
                            </ScrollViewer>
                        </Grid>
                    </Popup>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>

    <!-- 当 IsEnabled 为 false 时,改变背景色 -->
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Background" Value="LightGray"/>
            <Setter Property="Foreground" Value="DarkGray"/>
            <Setter Property="BorderBrush" Value="Gray"/>
        </Trigger>
    </Style.Triggers>
</Style>

<Style x:Key="DataGridStyles" TargetType="DataGrid">
    <!--<Setter Property="ColumnHeaderStyle" Value="{DynamicResource ColumnHeaderStyle}"></Setter>
    <Setter Property="CellStyle" Value="{DynamicResource CellStyle}"></Setter>
    <Setter Property="RowStyle" Value="{DynamicResource RowStyle}"></Setter>-->
    <!-- <Setter Property="EnableRowVirtualization" Value="True"></Setter> -->
    <!-- <Setter Property="GridLinesVisibility" Value="None"></Setter> -->
    <!-- <Setter Property="CanUserAddRows" Value="False"></Setter> -->
    <!-- <Setter Property="AutoGenerateColumns" Value="False"></Setter> -->
    <Setter Property="IsEnabled" Value="True"></Setter>
    <Setter Property="HeadersVisibility" Value="Column"></Setter>
    <!--网格线颜色-->
    <Setter Property="Background" Value="White" />
</Style>
<Style x:Key="ColumnHeaderStyles" TargetType="DataGridColumnHeader">
    <Setter Property="Height" Value="35"></Setter>
    <Setter Property="FontSize" Value="13"></Setter>
    <Setter Property="Background" Value="#F2F2F2"></Setter>
    <Setter Property="BorderThickness" Value="0,0,1,1"></Setter>
    <Setter Property="BorderBrush" Value="Black"></Setter>
    <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
    <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
</Style>
<Style x:Key="RowStyles" TargetType="DataGridRow">
    <Setter Property="Cursor" Value="Hand"></Setter>
    <Setter Property="BorderBrush" Value="Black"/>
    <Setter Property="BorderThickness" Value="0,0,0,1"/>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="true">
            <Setter Property="Background" Value="#F2F2F2"/>
        </Trigger>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background"  Value="Blue" />
        </Trigger>
    </Style.Triggers>
</Style>
<Style x:Key="CellStyles" TargetType="DataGridCell">
    <Setter Property="Height" Value="35"></Setter>
    <Setter Property="FontSize" Value="15"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="DataGridCell">
                <Border x:Name="Bg" Background="Transparent" BorderThickness="0" UseLayoutRounding="True" BorderBrush="#FFCBCBCB">
                    <ContentPresenter HorizontalAlignment="Center"  VerticalAlignment="Center" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

`

posted on 2025-02-09 17:06  每天一点点进步  阅读(112)  评论(0)    收藏  举报