原文:潜移默化学会WPF(转载篇)--屏幕显示Label,鼠标移上去变成textBox
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="" Width="" Loaded="Window_Loaded">
<Window.Resources>
<Style x:Key="LabelTemp" TargetType="Label">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Label">
<Grid >
<TextBox x:Name="tb" Text="{TemplateBinding Content}" Visibility="Hidden" Width="" Height=""
HorizontalAlignment="Center" VerticalAlignment="Top" FontSize=""></TextBox>
<Label x:Name="labReal" Content="{TemplateBinding Content}" Width="" Height=""
HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="" ></Label>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="tb" Property="Visibility" Value="Visible">
</Setter>
<Setter TargetName="labReal" Property="Visibility" Value="Hidden"></Setter>
</Trigger>
<Trigger Property="IsMouseOver" Value="false">
<Setter TargetName="labReal" Property="Content" Value="{Binding ElementName=tb,Path=Text}"></Setter>
</Trigger> </ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="104*" />
<ColumnDefinition Width="174*" />
</Grid.ColumnDefinitions>
<Label Name="lab" Style="{StaticResource LabelTemp}" VerticalAlignment="Top">Demo Label
</Label>
</Grid>
</Window>
原文地址 http://topic.csdn.net/u/20090324/14/349de2ff-f12e-4d7a-8a37-ca3318b63b51.html