首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

WPF,TextBlock的这种写法是什么属性支持的?该如何解决

2013-09-09 
WPF,TextBlock的这种写法是什么属性支持的?TextBlock TextTextBlock Button /fgfgfg /TextBlock

WPF,TextBlock的这种写法是什么属性支持的?
<TextBlock Text="TextBlock" >
    <Button />
    fgfgfg 
</TextBlock>

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

[解决办法]

DockPanel myDockPanel = new DockPanel(); //定义停靠容器控件 
Rectangle rect1 = new Rectangle(); //定义一个矩形

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


xxxx.Children.Add
[解决办法]


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楼主可以看看
[解决办法]
namespace System.Windows.Controls
{
[Localizability(LocalizationCategory.Text), ContentProperty("Inlines")]
public class TextBlock : FrameworkElement, IContentHost, IAddChildInternal, IAddChild, IServiceProvider
{
           ......................


一点都不读源代码,只是别人说“用吧”于是你就用了控件,怎么可能成为专业的开发人员呢?
[解决办法]
再来看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
{



[解决办法]

  // 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的定义哦~~~~~

热点排行