其中在模板中的数据配置是:
<Style TargetType="Button" x:Key="WTextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border x:Name="border1" Height="{TemplateBinding Height}" BorderThickness="1" CornerRadius="8" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Tag="{TemplateBinding Button.DataContext}" DataContext="{TemplateBinding Button.Content}">
<TextBox Name="TextContent" Margin="5,0,5,0" Height="{TemplateBinding Height}" BorderThickness="0" FontSize="{TemplateBinding FontSize}">
<TextBox.Resources>
<VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.5" Stretch="None" AlignmentX="Left">
<VisualBrush.Visual>
<TextBlock FontStyle="Normal" Margin="5,0,5,0" FontSize="{Binding ElementName=textBox1,Path=FontSize}" Foreground="Black" Text="{Binding ElementName=border1,Path=DataContext}"/>
</VisualBrush.Visual>
</VisualBrush>
</TextBox.Resources>
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="FontSize" Value="{Binding ElementName=textBox1,Path=FontSize}"/>
<Setter Property="Foreground" Value="Black" />
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="CaretBrush" Value="Black"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="AcceptsReturn" Value="True"/>
<Style.Triggers>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Background" Value="{StaticResource HelpBrush}"/>
</Trigger>
<Trigger Property="Text" Value="">
<Setter Property="Background" Value="{StaticResource HelpBrush}"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border1" Property="Border.Effect">
<Setter.Value>
<DropShadowEffect Color="{Binding ElementName=border1,Path=Tag}" ShadowDepth="0" BlurRadius="20" Opacity="1"/>
</Setter.Value>
</Setter>
<Setter TargetName="border1" Property="Border.BorderBrush" Value="{Binding ElementName=border1,Path=Tag}"></Setter>
</Trigger>
<DataTrigger Binding="{Binding ElementName=textBox1,Path=IsKeyboardFocused}" Value="True">
<Setter TargetName="border1" Property="Border.Effect">
<Setter.Value>
<DropShadowEffect Color="{Binding ElementName=border1,Path=Tag}" ShadowDepth="0" BlurRadius="20" Opacity="1"/>
</Setter.Value>
</Setter>
<Setter TargetName="border1" Property="Border.BorderBrush" Value="{Binding ElementName=border1,Path=Tag}"></Setter>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
var UserTemp = TBUserName.Template;
TextBox TBUserTB = BUserName.Template.FindName("TextContent",TBUserName) as TextBox;
string UserName = TBUserTB.Text;