zoukankan      html  css  js  c++  java
  • What is the difference between ContentPresenter and ContentControl?

    If you look at these two classes in reflector, you will notice the main difference between them: ContentControl derives from Control, and ContentPresenter doesn’t.

    ContentControl is a control that knows how to display content. If you’ve been reading my blog, you’re probably familiar with ItemsControl by now, which is a control that knows how to display a collection of data. ContentControl is the equivalent to ItemsControl, but it is used to display non-collections instead. Some classic examples of controls that derive from ContentControl are Button and Label. Its most important property is the Content DependencyProperty, of type object.

    ContentPresenter is an element that is useful inside the template of a ContentControl, and is used to specify where you want its content to be placed. For example, in the markup above I placed a ContentPresenter inside the Border because I want the Content of the Button (”Hello”) to appear inside the Border. If you remove the ContentPresenter, you will notice that “Hello” is no longer displayed. If you add elements before or after, you will notice that “Hello” will show up in the location where the ContentPresenter is placed in the layout pass.

    The ContentPresenter tag in the markup above is equivalent to the following:

        <ContentPresenter Content=”{TemplateBinding Content}” ContentTemplate=”{TemplateBinding ContentTemplate}” ContentTemplateSelector=”{TemplateBinding ContentTemplateSelector}” Margin=”10″/>

    A long time ago, you had to be explicit about where the Content, ContentTemplate and ContentTemplateSelector properties came from. We decided to make this implicit because we realized this is what people want most of the time. If, for some reason, you don’t want to use the Content of your ContentControl in its template, and want to use some other data instead, you can set the Content property of the ContentPresenter explicitly. For example, try replacing the ContentPresenter in the markup above with the following:

        <ContentPresenter Content=”{TemplateBinding Background}” Margin=”10″/>

    You will notice that the Button will display “#FF4682B4″ instead of “Hello”, even though we set its Content property to “Hello”.

    In summary: ContentControl is a control that uses a template to display a single piece of content, and ContentPresenter is used to specify where the content should go in the ContentControl’s template.

    website:http://www.beacosta.com/blog/?p=38

    reflector:http://www.red-gate.com/products/reflector/

  • 相关阅读:
    数据库的规范和SQL优化技巧总结
    新版Intellij idea破解方法(插件IDE Eval Reset)
    容易遗忘的知识点总结
    Java如何搭建脚手架(自动生成通用代码),创建自定义的archetype(项目模板)
    阿里云服务器域名解析和ICP域名备案
    云服务器通过ip无法访问
    FirewallD is not running 远程服务器开启端口报错
    [prerender-spa-plugin] Unable to prerender all routes! 内网打包报错(Navigation Timeout Exceeded)
    vue-cli中的 mode模式、env环境文件,以及其中定义的环境变量
    绘制柱状图和横向条形图,带数据标签!!!
  • 原文地址:https://www.cnblogs.com/liangouyang/p/1311750.html
Copyright © 2011-2022 走看看