<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="300" Width="300" 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="40" Height="20" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="12"></TextBox> <Label x:Name="labReal" Content="{TemplateBinding Content}" Width="40" Height="30" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="12" ></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
分类: 他山之石,WPF,WPF企业工作技巧 好文要顶 关注我 收藏该文 AYUI框架关注 - 152
粉丝 - 841 +加关注 0 0 « 上一篇:C# 训练场(四)创建系统热键,并向活动窗口输入信息
» 下一篇:潜移默化学会WPF(绚丽篇)--热烈欢迎RadioButton,改造成功,改造成ImageButton,新版导航