zoukankan      html  css  js  c++  java
  • 潜移默化学会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

  • 相关阅读:
    loj6158 A+B Problem (扩展KMP)
    2017CodeM初赛B场
    Codeforces Round #421(div 2)
    CF821E(多次矩阵快速幂)
    Codechef-ANCESTOR(树套树/CDQ分治)
    Codechef-BLACKCOM(树形背包dp)
    Codechef-CHEFPRAD(找事件点+贪心)
    洛谷 p3391
    luogu p3369
    LOJ10082
  • 原文地址:https://www.cnblogs.com/AaronYang/p/2505860.html
Copyright © 2011-2022 走看看