[OSS 2022/Tablecloth] C# WPF Textbox 워터마크(힌트) 생성 이슈

OOSUlZ·2022년 9월 1일
0

tablecloth

목록 보기
1/1

Tablecloth 프로젝트 이슈 선정

C# WPF Textbox 워터마크(힌트) 생성

오픈소스 프로젝트를 참여하던 중, 텍스트 검색박스에 워터마크(힌트)를 표시한다면 사용자가 검색박스를 더욱 더 활용할 수 있다고 판단하여 워터마크(힌트)기능을 추가하는 것을 건의하였다.

[이슈 게시물]

https://github.com/yourtablecloth/TableCloth/issues/91

구현 전

구현 후

이 기능을 구현하기 위해 멘토님과 토의를 했었고 그 결과 참고한 게시물의 수많은 답변 중
이 코드를 변형하여 구현하였다.
게시물 출처 : https://stackoverflow.com/questions/833943/watermark-hint-placeholder-text-in-textbox

<TextBox>
    <TextBox.Style>
        <Style TargetType="TextBox" xmlns:sys="clr-namespace:System;assembly=mscorlib">
            <Style.Resources>
                <VisualBrush x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="None">
                    <VisualBrush.Visual>
                        <Label Content="MM:SS:HH AM/PM" Foreground="LightGray" />
                    </VisualBrush.Visual>
                </VisualBrush>
            </Style.Resources>
            <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>
    </TextBox.Style>
</TextBox>

코드 변경 세부내역

profile
천천히,꾸준하게

0개의 댓글