안녕하세요.
로그인 페이지를 만들고 있습니다.
이메일과 비밀번호 칸이 있습니다.
이메일 칸은 TextBox로 구현했구요, 비밀번호칸은 PasswordBox로 구현하고 있습니다.
TextBox에 사용한 Style 소스로 같이 구현했는데 PaswordBox칸은 Tag가 나타나지 않습니다.
<!-- Email -->
<TextBox Style="{StaticResource TextBoxIDPwd}" Tag="Email" />
<!-- Password -->
<PasswordBox Style="{StaticResource Test1}" Tag="Password"/>
<!-- TexBox Style 설정 -->
<Style x:Key="TextBoxIDPwd" TargetType="{x:Type TextBox}" BasedOn="{StaticResource BaseStyle}" >
...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Grid>
<Border x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
<TextBlock IsHitTestVisible="False"
Text="{TemplateBinding Tag}"
x:Name="placeholder"
FontFamily="{StaticResource LatoThin}"
Padding="{TemplateBinding Padding}"
VerticalAlignment="Center"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
Foreground="{StaticResource ForegroundVeryDarkBrush}" >
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}" Value="">
<!-- PaswordBox => <DataTrigger Binding="{Binding (local:PasswordBoxProperties.HasText), RelativeSource={RelativeSource TemplatedParent}}" Value="False"> -->
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
</Setter.Value>
</Setter>
</Style>
<!-- PasswordBox Style 설정 -->
<Style x:Key="Test1" TargetType="{x:Type PasswordBox}" BasedOn="{StaticResource BaseStyle}" >
...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type PasswordBox}">
<Grid>
<Border x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
<TextBlock IsHitTestVisible="False"
Text="{TemplateBinding Tag}"
x:Name="placeholder"
FontFamily="{StaticResource LatoThin}"
Padding="{TemplateBinding Padding}"
VerticalAlignment="Center"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
Foreground="{StaticResource ForegroundVeryDarkBrush}" >
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding (local:PasswordBoxProperties.HasText), RelativeSource={RelativeSource TemplatedParent}}" Value="False">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="#FF7EB4EA"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="#FF569DE5"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
PasswordBox의 경우 위에 소스를 복붙하고 TargetType을 PasswordBox로 설정해주었습니다.
PasswordBox는 실링되어 있어서 별도의 cs를 만들어서 이벤트 처리등등을 하고 있습니다.
저장소에 사용한 소스 ( PasswordBoxProperties.cs, LoginPage.xaml, Texts.xaml )를 업로드 합니다.
GitHub : https://github.com/SSstupid/WPF_Start_Records/tree/main/PasswordBox%20테스트
감사합니다.
22.04.04 수정
PasswordBox 의 Tag 를 Binding 해서 placeholder 로 보여주는 style 을 만들었다.
근데 style 안에서 AttachedProperty 를 사용했는데 Tag 가 placeholder 로 표시되지 않는다.
질문이 잘 정리됬네요.
위에 긴 글이 이 두줄로 축약되고 이해가 잘됩니다.