zoukankan      html  css  js  c++  java
  • 简单使用控件模板2

    简单使用控件模板

    <Window.Resources>
            <ControlTemplate x:Key="buttontemplate" TargetType="{x:Type Button}">
                <Border BorderBrush="Orange" BorderThickness="{TemplateBinding Button.BorderThickness}" CornerRadius="3"
                        Background="Red" TextBlock.Foreground="Black" Margin="30">
                    <ContentPresenter RecognizesAccessKey="True" HorizontalAlignment="Center"
                                       VerticalAlignment="Center" Content="{TemplateBinding Button.Content}"></ContentPresenter>
                </Border>
            </ControlTemplate>
        </Window.Resources>
        <StackPanel>
            <Button FontSize="15" Template="{StaticResource ResourceKey=buttontemplate}" BorderThickness="10" Content="Hello"></Button>
            <Button FontSize="15" Template="{StaticResource ResourceKey=buttontemplate}" BorderThickness="4" Content="您好"></Button>
        </StackPanel>

    控件模板触发器

    <Window.Resources>
            <ControlTemplate x:Key="buttontemplate" TargetType="{x:Type Button}">
                <Border Name="border" BorderBrush="Orange" BorderThickness="{TemplateBinding Button.BorderThickness}" CornerRadius="3"
                        Background="Red" TextBlock.Foreground="Black" Margin="30">
                    <StackPanel>
                            <Rectangle Name="FocusCue" Visibility="Hidden" Stroke="Black"
                                        StrokeThickness="3" StrokeDashArray="1 2" SnapsToDevicePixels="True"></Rectangle>
                     
                        <ContentPresenter RecognizesAccessKey="True" HorizontalAlignment="Center"
                                           VerticalAlignment="Center" Content="{TemplateBinding Button.Content}">
                       
                        </ContentPresenter>
                    </StackPanel>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter TargetName="border" Property="Background" Value="White"/>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="FocusCue" Property="Visibility" Value="Visible"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
           
        </Window.Resources>
        <StackPanel>
            <Button Template="{StaticResource ResourceKey=buttontemplate}" Content="Hello"/>
        </StackPanel>

  • 相关阅读:
    北航OO第三单元总结
    北航OO第二单元总结
    提问回顾和个人总结
    Unity 制作不规则形状button
    Unity 3D手游对不同分辨率屏幕的UI自适应
    软工结队作业
    CSDN app分析
    软工作业——求交点
    软工第一次作业
    软工热身作业
  • 原文地址:https://www.cnblogs.com/KimhillZhang/p/2422493.html
Copyright © 2011-2022 走看看