Panel内容模型

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

•Canvas

•DockPanel

•Grid

•TabPanel

•ToolBarOverflowPanel

•UniformGrid

•StackPanel

•ToolBarPanel

•VirtualizingPanel

•VirtualizingStackPanel

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

二、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指定的)样式。

代码如下:
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">


























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
{
///
/// Interaction logic for Panel内容模型.xaml
///

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 演示代码如下:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TextBlock模型" Height="300" Width="300">






BlockText 控件XAML示例



TextBlock支持以下的几种流显示样式:

粗体(Bold)

斜体(Italic)

下划线(Underline)

超链接

Span设置字体、颜色等



Inline UI 容器

你可能感兴趣的:(WPF,windows,panel,controls,linq)