<TextBlock Text="TextBlock" >
    <Button />
    fgfgfg 
</TextBlock>使用集合语法给属性赋值,起码得有个属性啊,就像ListBox的Item属性一样。
TextBlock这种写法,是由TextBlock的什么属性支持的?

解决方案 »

  1.   

    DockPanel myDockPanel = new DockPanel(); //定义停靠容器控件 
    Rectangle rect1 = new Rectangle(); //定义一个矩形DockPanel.SetDock(rect1, Dock.Top); //设置矩形的停靠位置是置顶
    myDockPanel.Children.Add(rect1); //容器控件里添加这个矩形
    xxxx.Children.Add
      

  2.   

    TextBlock t = new TextBlock();
                Button b=new Button();
                TextBlock c=new TextBlock();
                c.Text="button";
                b.Content=c;
                t.Inlines.Add(b);
                this.Container.Children.Add(t);
    textbook的inlines楼主可以看看
      

  3.   

    namespace System.Windows.Controls
    {
    [Localizability(LocalizationCategory.Text), ContentProperty("Inlines")]
    public class TextBlock : FrameworkElement, IContentHost, IAddChildInternal, IAddChild, IServiceProvider
    {
               ......................一点都不读源代码,只是别人说“用吧”于是你就用了控件,怎么可能成为专业的开发人员呢?
      

  4.   

    再来看ListBox的父类ItemsControl是怎样定义的呢?namespace System.Windows.Controls
    {
    [DefaultEvent("OnItemsChanged"), DefaultProperty("Items"), Localizability(LocalizationCategory.None, Readability = Readability.Unreadable), ContentProperty("Items"), StyleTypedProperty(Property = "ItemContainerStyle", StyleTargetType = typeof(FrameworkElement))]
    public class ItemsControl : Control, IAddChild, IGeneratorHost, IContainItemStorage
    {
      

  5.   

     inlines属性添加的是Inline元素啊,为什么能添加Button、fgfgfg呢?
      

  6.   


      // Summary:
        //     Represents a collection of System.Windows.Documents.Inline elements. System.Windows.Documents.InlineCollection
        //     defines the allowable child content of the System.Windows.Documents.Paragraph,
        //     System.Windows.Documents.Span, and System.Windows.Controls.TextBlock elements.
        [ContentWrapper(typeof(Run))]
        [WhitespaceSignificantCollection]
        [ContentWrapper(typeof(InlineUIContainer))]
        public class InlineCollection : TextElementCollection<Inline>, IList, ICollection, IEnumerable
        {
            // Summary:
            //     Gets the first System.Windows.Documents.Inline element within this instance
            //     of System.Windows.Documents.InlineCollection.
            //
            // Returns:
            //     The first System.Windows.Documents.Inline element within this instance of
            //     System.Windows.Documents.InlineCollection.
            public Inline FirstInline { get; }
            //
            // Summary:
            //     Gets the last System.Windows.Documents.Inline element within this instance
            //     of System.Windows.Documents.InlineCollection.
            //
            // Returns:
            //     The last System.Windows.Documents.Inline element within this instance of
            //     System.Windows.Documents.InlineCollection.
            public Inline LastInline { get; }        // Summary:
            //     Adds an implicit System.Windows.Documents.Run element with the given text,
            //     supplied as a System.String.
            //
            // Parameters:
            //   text:
            //     Text set as the System.Windows.Documents.Run.Text property for the implicit
            //     System.Windows.Documents.Run.
            public void Add(string text);
            //
            // Summary:
            //     Adds an implicit System.Windows.Documents.InlineUIContainer with the supplied
            //     System.Windows.UIElement already in it.
            //
            // Parameters:
            //   uiElement:
            //     System.Windows.UIElement set as the System.Windows.Documents.InlineUIContainer.Child
            //     property for the implicit System.Windows.Documents.InlineUIContainer.
            public void Add(UIElement uiElement);
        }
    楼上的sp大大说的真没错 你还是没有看代码
    看看public void Add(UIElement uiElement);
    这里是uielement 意思就是ui元素都可以加啊
    仔细看看inlines的定义哦~~~~~