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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
XAML-Code
<Window x:Class="TextBoxFocus.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title=".Net-Snippets - TextBoxFocus" Height="360" Width="300">
<Window.Resources>
<!-- **************************************************************************************** <-->
<!-- ****************************** Farbverlauf "Hintergrund" ****************************** <-->
<!-- **************************************************************************************** <-->
<LinearGradientBrush x:Key="GridBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="DimGray" />
<GradientStop Offset=".59" Color="DarkGray" />
<GradientStop Offset=".60" Color="DarkGray" />
<GradientStop Offset="1" Color="DimGray" />
</LinearGradientBrush>
<!-- **************************************************************************************** <-->
<!-- **************************** Template für schwarze Buttons ***************************** <-->
<!-- **************************************************************************************** <-->
<ControlTemplate x:Key="BlackButton" TargetType="{x:Type Button}">
<Border BorderBrush="White" BorderThickness="1" CornerRadius="3">
<Border BorderBrush="DarkGray" BorderThickness="1" CornerRadius="3">
<Grid Name="ButtonGrid">
<Rectangle Name="ButtonRect">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="Gray" />
<GradientStop Offset="0.49" Color="DimGray" />
<GradientStop Offset="0.5" Color="DimGray" />
<GradientStop Offset="1" Color="Black" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" />
</Grid>
</Border>
</Border>
<ControlTemplate.Triggers>
<!-- Bei Mausbewegung über den Button ... -->
<Trigger Property="IsMouseOver" Value="True">
<!-- Buttonhintergrund heller darstellen -->
<Setter Property="Fill" TargetName="ButtonRect">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="Silver" />
<GradientStop Offset="1" Color="Black" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<!-- Leuchteffekt -->
<Setter Property="BitmapEffect">
<Setter.Value>
<OuterGlowBitmapEffect GlowColor="White" GlowSize="5" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Fill" TargetName="ButtonRect" Value="#FF000000" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!-- **************************************************************************************** <-->
<!-- ************************* Style-Template für "aktive Textboxen" ************************ <-->
<!-- **************************************************************************************** <-->
<Style x:Key="TextBoxStyleSilverWhite" TargetType="TextBox">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="Gainsboro"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="White"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="Yellow"/>
<Setter Property="BorderThickness" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid x:Name="MasterGrid" Background="{StaticResource GridBackgroundBrush}">
<Button Name="btnClose" Content="Schließen" Margin="0,0,0,15" Width="110" Height="30"
HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="White" Click="btnClose_Click"
Template="{DynamicResource BlackButton}" />
</Grid>
</Window>
C#-Code
public Window1()
{
InitializeComponent();
for( int i=0; i<10; i++ )
{
MasterGrid.Children.Add( new Label()
{
Margin = new Thickness( 10, i * 25 + 8, 0, 0 ),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Content = "Beschreibung Nr. " + (i+1), Foreground = Brushes.White
} );
MasterGrid.Children.Add( new TextBox()
{
Margin = new Thickness( 130, i * 25 + 10, 0, 0 ),
Width = 140, Height = 20, TabIndex = i+1,
Style = (Style)MasterGrid.FindResource("TextBoxStyleSilverWhite"),
Text = "TextBox Nr. " + (i+1)
} );
}
|