Panel内容模型

一、Panel内容模型
Panel内容模型指从System.Windows.Controls.Panel继承的控件,这些控件都是容器,可以在内部承载其他的控件和子容器。Panel内容模型包含的容器有:

•Canvas

•DockPanel

•Grid

•TabPanel

•ToolBarOverflowPanel

•UniformGrid

•StackPanel

•ToolBarPanel

•VirtualizingPanel

•VirtualizingStackPanel

•WrapPanel
对于Panel模型,其包含一个Children属性,表示其所有的子控件和子容器的集合,在XAML代码中可以省略<XXX.Children>标记.

二、Decorator内容模型
Decorator内容模型指的是从System.Windows.Controls.Decorator类继承的控件,主要是对其中的一个子元素的边缘进行修饰。Decorator模型的主要控件包含:

•AdornerDecorator

•Border

•BulletDecorator

•ButtonChrome

•ClassicBorderDecorator

•InkPresenter

•ListBoxChrome

•SystemDropShadowChrome

•Viewbox

Decorator模型包含一个Child属性,表示其包含的一个子元素(注意,只能是一个子元素(控件或容器,在容器中可以再添加其他的控件)),Child属性的XAML标记可以省略。
例如,对于一个TextBox添加一个边框,使用XAML语言定义

三、TextBlock模型
TextBlock模型实际上指的就是System.Windows.Controls.TextBlock类,它是一个用于显示少量流内容的轻量控件。其中包含一个InLines属性,支持 Inline 流内容元素的承载和显示。 支持的元素包括 AnchoredBlock、Bold(粗体字符串)、Hyperlink(超链接,在浏览器支持的模式下有效)、InlineUIContainer(承载其他控件的容器)、Italic(斜体字符串)、LineBreak(换行符)、Run(普通字符串)、Span(可以设置字体、颜色等的Span) 和 Underline(下划线)。

四、TextBox模型
System.Windows.Controls.TextBox类,实现的是可编辑的文本框,文本框的内容由字符串类型的Text属性指定,并且整个TextBox的内容使用共同的(即TextBox指定的)样式。

代码如下:
<Window x:Class="WpfApplication1.Panel内容模型"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Panel内容模型" Height="300" Width="300" Loaded="Window_Loaded">
   
    <StackPanel Name="mainPanel">
        <StackPanel Name="panelA">
            <StackPanel.Children>
                <Button>Button A</Button>
            </StackPanel.Children>
        </StackPanel>
        <Button>Button B</Button>
        <StackPanel Name="panelB">
        </StackPanel>
       
        <TextBlock Text="Decorator内容模型" HorizontalAlignment="Center"></TextBlock>
       
        <!--Decorator内容模型 对于一个TextBox添加一个边框,使用XAML语言定义-->
        <StackPanel Name="mainPane2">
            <Border BorderThickness="5" BorderBrush="DarkBlue" Margin="5">
                <Border.Child>
                    <TextBox Text="TextBox Content"/>
                </Border.Child>
            </Border>
        </StackPanel>
    </StackPanel>

  
</Window>

C# 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Panel内容模型.xaml
    /// </summary>
    public partial class Panel内容模型 : Window
    {
        public Panel内容模型()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
             // 定义一个Button  
            Button btn = new Button();  
            btn.Content = "Button C";
            // 将Button添加到StackPanel中  
            panelB.Children.Add(btn);

            //获得Decorator内容模型
            getContentModel();
        }

        private void getContentModel()
        {
              // 定义一个Border对象,并设置其边框的大小,颜色,外边距 
             Border border = new Border();  
             border.BorderThickness = new Thickness(5); 
             border.BorderBrush = new SolidColorBrush(Colors.DarkRed);
             border.Margin = new Thickness(5); 
            // 定义一个TextBox对象  
            TextBox textBox = new TextBox();
            textBox.Text = "TextBox Content Text";
            // 使用Border修饰TextBox的边框
            border.Child = textBox;
            // 将Border添加到StackPanel中 
            mainPane2.Children.Add(border);
        }
    }
}

TextBlock 演示代码如下:
<Window x:Class="WpfApplication1.TextBlock模型"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TextBlock模型" Height="300" Width="300">
   
    <StackPanel Orientation="Horizontal">
        <Border BorderThickness="2" Margin="5" BorderBrush="Black">
            <TextBlock Margin="5" TextWrapping="WrapWithOverflow">  
                <TextBlock.Inlines> 
                    <Bold> 
                        <Run>BlockText 控件XAML示例</Run>
                    </Bold> 
                    <!--换行-->
                    <LineBreak/> 
                    <Run>TextBlock支持以下的几种流显示样式:</Run> 
                    <LineBreak/> 
                    <Bold>粗体(Bold)</Bold>
                    <LineBreak/> 
                    <Italic>斜体(Italic)</Italic>
                    <LineBreak/>
                    <Underline>下划线(Underline)</Underline>
                    <LineBreak/> 
                    <Hyperlink NavigateUri="http://www.baidu.com">超链接</Hyperlink>
                    <LineBreak/> 
                    <Span Foreground="Red" FontSize="18">Span设置字体、颜色等</Span>
                    <LineBreak /> 
                    <InlineUIContainer> 
                        <StackPanel Background="AntiqueWhite" Margin="5"> 
                            <TextBlock>Inline UI 容器</TextBlock> 
                            <Button Content="按钮" Width="80" />
                        </StackPanel> 
                    </InlineUIContainer> 
                </TextBlock.Inlines>
            </TextBlock>
        </Border>
        <Border BorderThickness="2" Margin="5" BorderBrush="Black">
            <TextBlock Margin="5" TextWrapping="WrapWithOverflow" x:Name="textBlock">
                <TextBlock.Inlines> 
                    <Bold> 
                        <Run x:Name="title"></Run>
                    </Bold> 
                    <LineBreak x:Name="line"/>
                    <InlineUIContainer x:Name="container">
                        <StackPanel Background="AntiqueWhite" Margin="5" x:Name="panel">
                           
                        </StackPanel> 
                    </InlineUIContainer> 
                </TextBlock.Inlines> 
            </TextBlock>
        </Border>
    </StackPanel>
</Window>

C# 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for TextBlock模型.xaml
    /// </summary>
    public partial class TextBlock模型 : Window
    {
        public TextBlock模型()
        {
            InitializeComponent();

             // 设置Inline对象的属性值  
            title.Text = "TextBlock 控件代码示例"; 
            // 添加Inline对象  
            Run content = new Run("TextBlock支持以下的几种流显示样式:"); 
            Bold bold = new Bold(new Run("粗体"));  
            Italic italic = new Italic(new Run("斜体"));
            Underline underline = new Underline(new Run("下划线"));
            Hyperlink hyperlink = new Hyperlink(new Run("超链接"));
            hyperlink.NavigateUri = new Uri("http://www.microsoft.com"); 
            Span span = new Span(new Run("Span设置字体、颜色等")); 
            span.Foreground = new SolidColorBrush(Colors.Green); 
            span.FontSize = 18;
            textBlock.Inlines.InsertBefore(container, content);
            textBlock.Inlines.InsertBefore(container, new LineBreak());
            textBlock.Inlines.InsertBefore(container, bold);
            textBlock.Inlines.InsertBefore(container, new LineBreak()); 
            textBlock.Inlines.InsertBefore(container, italic); 
            textBlock.Inlines.InsertBefore(container, new LineBreak()); 
            textBlock.Inlines.InsertBefore(container, underline); 
            textBlock.Inlines.InsertBefore(container, new LineBreak());
            textBlock.Inlines.InsertBefore(container, hyperlink); 
            textBlock.Inlines.InsertBefore(container, new LineBreak()); 
            textBlock.Inlines.InsertBefore(container, span);
            textBlock.Inlines.InsertBefore(container, new LineBreak());
            // 设置InlineUIContainer的成员 
            panel.Children.Add(new TextBlock(new Run("InlineUIContainer"))); 
            Button button = new Button(); 
            button.Content = "Button"; 
            button.Width = 80; 
            panel.Children.Add(button);
        }
    }
}

你可能感兴趣的:(windows,LINQ,Panel,controls)