zoukankan      html  css  js  c++  java
  • WP模板

    ContentControl有两个属性:

            // 摘要:
            //     获取或设置 System.Windows.Controls.ContentControl 依赖项属性的值。
            //
            // 返回结果:
            //     一个包含控件内容的对象。默认值为 null。
            public object Content { get; set; }
            //
            // 摘要:
            //     获取或设置用于显示 System.Windows.Controls.ContentControl 内容的数据模板。
            //
            // 返回结果:
            //     用于显示 System.Windows.Controls.ContentControl 内容的数据模板。
            public DataTemplate ContentTemplate { get; set; }

    Content用来表示其内容,可以是控件控件笔刷文字等内容,ContentTemplate为DataTemplate类型的模板,其为显示效果。

    Control和FrameElement的去别在于前者有Template属性。

                <Button Content="Click me!" HorizontalAlignment="Center" VerticalAlignment="Center">
                    <Button.Style>
                        <Style TargetType="Button">
                            <Setter Property="BorderBrush" Value="{StaticResource PhoneAccentBrush}" />
                            <Setter Property="BorderThickness" Value="6" />
                            <Setter Property="Background" Value="{StaticResource PhoneChromeBrush}" />
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="Button">
                                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="12">
                                          <ContentPresenter Content="{TemplateBinding Content}" 
                                                              ContentTemplate="{TemplateBinding ContentTemplate}"
                                                              Margin="{TemplateBinding Padding}"
                                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
    </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </Button.Style> </Button>

     ContentPresenter刚好对应control中的两个属性Content和ContentTemplate。object类型的Content与其相一致,当button中的属性不会受ContentPresenter的控制时,

    说明Button的属性是本身的熟悉,需要绑定。如ForeGround,是字体的属性,直接就在Content里面一起绑定了。如BackGround是Button的属性,非内容属性。

    /// <summary>
            /// 遍历指定的UIControl里面的元素——引用方式DumpVisualTree(listBox, 0);
            /// </summary>
            /// <param name="parent"></param>
            /// <param name="indent"></param>
            void DumpVisualTree(DependencyObject parent, int indent)
            {
                TextBlock txtblk = new TextBlock();
                txtblk.Text = String.Format("{0}{1}", new string(' ', 4 * indent),
                                                      parent.GetType().Name);
                dumpTreeItemsControl.Items.Add(txtblk);
    
                int numChildren = VisualTreeHelper.GetChildrenCount(parent);
    
                for (int childIndex = 0; childIndex < numChildren; childIndex++)
                {
                    DependencyObject child = VisualTreeHelper.GetChild(parent, childIndex);
                    DumpVisualTree(child, indent + 1);
                }
            }
  • 相关阅读:
    IE设置cookie问题。
    正则表达式。
    Git和SVN区别
    点滴MarkDown~
    浏览器页面是否缩放问题。
    我理解的灰度发布。
    有衬线字体和无衬线字体
    移动开发规范
    Thunderbird 如何接收 Foxmail 发出的会议邀请。。
    移动端 CSS sprites 的 background-size 如何计算的。
  • 原文地址:https://www.cnblogs.com/lzhp/p/3222848.html
Copyright © 2011-2022 走看看