zoukankan      html  css  js  c++  java
  • sl基础(二)

    理解Styles和ControlTemplates

    理解ResourceDictionaries

    理解用户自定义控件

    ControlTemplate从Control继承 而Control中有Template属性

    定义ControlTemplate有三种方式:

    内联定义:

    <ToolTip>

        <ToolTip.Template>

            <ControlTemplate TargetType=”ToolTip>

                 ………

            </ControlTemplate>

        </ToolTip.Template>

    </ToolTip>

    资源引用:

    <UserControl.Resources>

    <ControlTemplate x:Key=”tooltip” TargetType=”ToolTip”>

    …….

    </ControlTemplate>

    </UserControl.Resources>

    <Grid x:Name=”LayoutRoot” Background=”White”>

    <ToolTip>

    <ToolTip.Template>

              <StaticResources ResourceKey=”toolTip”/>

    </ToolTip.Template>

    </ToolTip>

    </Grid>

    样式引用 :(常用方式)

    <UserControl.Resources>

    <ControlTemplate x:Key=”tooltip” TargetType=”ToolTip”>

              <Setter Property=”Template”>

                    <Setter.Value>

                            <ControlTemplate TargetType=”ToolTip”>

                             </ControlTemplate>

                    </Setter.Value>

              </Setter>

    </ControlTemplate>

    </UserControl.Resources>

    <ToolTip Style=”{StaticResource toolTip}”/>

    DataPicker的水印处理

    public class MyDatePicker : DatePicker
        {
            public override void OnApplyTemplate()
            {
                base.OnApplyTemplate();
                var datePickerTextBox = GetTemplateChild("TextBox") as DatePickerTextBox;
                datePickerTextBox.Watermark = "选择日期....";
                datePickerTextBox.TextChanged += datePickerTextBox_TextChanged;
            }
            private void datePickerTextBox_TextChanged(object sender, TextChangedEventArgs e)
            {
                var datePickerTextBox = GetTemplateChild("TextBox") as DatePickerTextBox;
                datePickerTextBox.Watermark = "选择日期...";
            }
        }

    FallbackValue属性:

    <TextBlock Text=”{Binding Path=Name, FallbackValue=’无效值’}”/>

    当绑定源不存在Name属性时,TextBlock就会显示无效值

    <TextBlock Text=”{Binding Path=Data,StringFormat=’Now is \{0:yyyy-M-dd}’}”/>

    园子里面看到统一设置样式的文章,感觉没有CSS来的方便,可能是刚入门还没有找到有效方法。<Application.Resources>
        <!--   统一设置按钮样式 TargetType应用的类型 x:Key 名称  -->
        <!--   引用方式: Style=" { StaticResource ButtonStyle }"  -->
        <Style TargetType="Button" x:Key="ButtonStyle">
            <Setter Property="Background" Value="Red"></Setter>
            <Setter Property="Height" Value="50"/>
            <Setter Property="Width" Value="100"/>
            <Setter Property="Margin" Value="10"/>
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="FontSize" Value="16"/>
        </Style>
    </Application.Resources>

  • 相关阅读:
    C++成员变量与函数内存分配
    Sqlite ContentProvider Loader 上下文 对话框
    好书好人生--读书的步骤
    小智慧40
    流媒体开发之-直播界面切换电视台频道
    HDU 4617Weapon(两条异面直线的距离)
    BON取代半岛电视,美国人要“换口味”了吗?
    【Todo】Lucene系统学习
    Zookeeper学习 & Paxos
    C++中的虚继承 & 重载隐藏覆盖的讨论
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1958881.html
Copyright © 2011-2022 走看看