• 潜移默化学会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="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

  • 相关阅读:
    多线程
    文件上传案例及多线程版本
    TCP、UDP网络通信
    刷题:蘑菇街最小移动次数
    刷题:蘑菇街回文串
    刷题:蘑菇街
    Range Sum Query
    Submission Details
    Reverse Words in a String
    Counting Bits
  • 原文地址:https://www.cnblogs.com/AaronYang/p/2505860.html
Copyright © 2020-2023  润新知