-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPlaceholderTextResources.xaml
More file actions
78 lines (72 loc) · 3.78 KB
/
PlaceholderTextResources.xaml
File metadata and controls
78 lines (72 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Menees.Windows.Presentation">
<!--Based on https://prabu-guru.blogspot.com/2010/06/how-to-add-watermark-text-to-textbox.html -->
<ControlTemplate x:Key="Menees.Windows.Presentation.PlaceholderText.ControlTemplate">
<ControlTemplate.Resources>
<Storyboard x:Key="enterGotFocus" >
<DoubleAnimation Duration="0:0:0.2" To=".2" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Message"/>
</Storyboard>
<Storyboard x:Key="exitGotFocus" >
<DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Message"/>
</Storyboard>
<Storyboard x:Key="enterHasText" >
<DoubleAnimation Duration="0:0:0.1" From=".2" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Message"/>
</Storyboard>
<Storyboard x:Key="exitHasText" >
<DoubleAnimation Duration="0:0:0.4" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Message"/>
</Storyboard>
</ControlTemplate.Resources>
<Border Name="Bd"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Top" Margin="1" />
<TextBlock x:Name="Message"
Text="{TemplateBinding local:PlaceholderTextHelper.PlaceholderText}"
Foreground="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" IsHitTestVisible="False" Opacity="0.8"
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="6,1,0,0"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Opacity" Value="1" TargetName="Bd"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="local:PlaceholderTextHelper.HasText" Value="False"/>
<Condition Property="IsFocused" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource enterGotFocus}"/>
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource exitGotFocus}"/>
</MultiTrigger.ExitActions>
</MultiTrigger>
<Trigger Property="local:PlaceholderTextHelper.HasText" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource enterHasText}"/>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource exitHasText}"/>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="Menees.Windows.Presentation.PlaceholderTextBox" TargetType="{x:Type TextBoxBase}">
<Setter Property="local:PlaceholderTextHelper.IsMonitoring" Value="True"/>
<Setter Property="local:PlaceholderTextHelper.PlaceholderText" Value="PlaceholderText" />
<Setter Property="Template" Value="{StaticResource Menees.Windows.Presentation.PlaceholderText.ControlTemplate}"/>
</Style>
<Style x:Key="Menees.Windows.Presentation.PlaceholderPasswordBox" TargetType="{x:Type PasswordBox}">
<Setter Property="local:PlaceholderTextHelper.IsMonitoring" Value="True"/>
<Setter Property="local:PlaceholderTextHelper.PlaceholderText" Value="Password" />
<Setter Property="Template" Value="{StaticResource Menees.Windows.Presentation.PlaceholderText.ControlTemplate}"/>
</Style>
</ResourceDictionary>