unmvyd

博客园 首页 新随笔 联系 订阅 管理
            <Style x:Key="tbStyle" TargetType="TextBox">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="TextBox">
                                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                                        <ScrollViewer Margin="0" x:Name="PART_ContentHost"></ScrollViewer>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="BorderBrush" Value="#FF0D5365"></Setter>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsKeyboardFocused, RelativeSource={RelativeSource Self}}" Value="false">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="TextBox">
                                            <Border Name="templateBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                                                <TextBlock Text="{TemplateBinding Text}" TextAlignment="Center" VerticalAlignment="Center" Foreground="{TemplateBinding Foreground}" TextTrimming="CharacterEllipsis" Padding="{TemplateBinding Padding}"/>
                                                
                                            </Border>
                                            <ControlTemplate.Triggers>
                                                
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                            <Trigger Property="IsFocused" Value="true">
                                <Setter Property="BorderBrush" Value="#FF0D5365"></Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
posted on 2024-06-07 16:05  准爵  阅读(2)  评论(0编辑  收藏  举报