Note - Tips - Trick - .Net

Lưu các thủ thuật, code mẫu, cách dùng về .Net

Radius textbox WPF with Text hint Radius textbox WPF with Text hint Radius textbox WPF with Text hint Radius textbox WPF with Text hint Radius textbox WPF with Text hint 1/5 (13 reviews)

Radius textbox WPF with Text hint

Đã đăng 2018-06-27 21:44:06 bởi K9
0 bình luận 1057 lượt xem
Radius textbox WPF with Text hint 1 /5 stars (1 reviews)
 
<Style TargetType="TextBox" x:Key="txbHintRadiusStyle" xmlns:sys="clr-namespace:System;assembly=mscorlib">
        <Style.Resources>
            <VisualBrush x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="None">
                <VisualBrush.Visual>
                    <Label Content="Nhập tài khoản" Foreground="Gray" />
                </VisualBrush.Visual>
            </VisualBrush>
        </Style.Resources>
        <Setter Property="Template" Value="{DynamicResource TextBoxRadiusControlTemplate}"></Setter>
        <Style.Triggers>
            <Trigger Property="Text" Value="{x:Static sys:String.Empty}">
                <Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
            </Trigger>
            <Trigger Property="Text" Value="{x:Null}">
                <Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="True">
                <Setter Property="Background" Value="White" />
            </Trigger>
        </Style.Triggers>
    </Style>
    <ControlTemplate x:Key="TextBoxRadiusControlTemplate" TargetType="{x:Type TextBoxBase}">
        <Border Background="{TemplateBinding Background}" 
                x:Name="Bd" BorderBrush="Black"
                BorderThickness="{TemplateBinding BorderThickness}" Padding="5 2 0 0" CornerRadius="10">
            <ScrollViewer x:Name="PART_ContentHost"/>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/>
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
            </Trigger>
            <Trigger Property="Width" Value="Auto">
                <Setter Property="MinWidth" Value="100"/>
            </Trigger>
            <Trigger Property="Height" Value="Auto">
                <Setter Property="MinHeight" Value="20"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

 

Cách dùng

<TextBox  Margin="5" Height="25" Style="{DynamicResource txbHintRadiusStyle}"></TextBox>

 

thành phẩm

Chia sẻ:
Thảo luận Hỏi và đáp Báo lỗi bài viết
Hủy bỏ   hoặc  
Hủy bỏ   hoặc  
Hủy bỏ   hoặc  

Chiến dịch

Kteam - Howkteam Free Education