1:内容控件(Content Controls)
2:条目控件(Items Controls)
3:文本控件(Text Controls)
4:范围控件(Range Controls)

一:内容控件
内容控件的最大的特征就是有一个Content属性,从前面的文章中,我们多多少少也知道Content接收的是一个Object类型,或许
我们会立即想到莫非Button就是一个内容控件,确实,Button算是一个内容控件,凡是内容控件都继承自ContentControl,因为
Content属性就是属于ContentControl。
<1>Button
<2>RepeatButton
一般用来实现“快进”,“快退”
Delay:作用就是按下时第一次触发Click的时间延迟。
Interval:每次click发生的时间间隔。

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Canvas>
<TextBox Canvas.Left="151" Canvas.Top="69" Height="33" Name="textBox1" Width="172" Text="0" />
<RepeatButton x:Name="test" Delay="100" Interval="100" Click="test_Click" Width="172"
Content="确定" Height="61" Canvas.Left="151" Canvas.Top="121" />
</Canvas>
</Window>
namespace WpfApplication1
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void test_Click(object sender, RoutedEventArgs e)
{
var num = Convert.ToInt32(textBox1.Text);
textBox1.Text = (++num).ToString();
}
}
}

<3>ToggleButton
从图中我们看到ToggleButton是CheckBox和RadioButton的基类。

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<CheckBox Content="CheckBox" Height="16" HorizontalAlignment="Left" Margin="96,137,0,0" Name="checkBox1"
VerticalAlignment="Top" IsThreeState="True" Indeterminate="checkBox1_Checked" />
</Grid>
</Window>
namespace WpfApplication1
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
} private void checkBox1_Checked(object sender, RoutedEventArgs e)
{
MessageBox.Show("不错");
}
}
}

二:条目控件

条目控件首先都是继承自ItemsControl,在ItemsControl中我们发现有两个比较有意思的属性,Items和ItemsSource。
Items:
从图中可以看出Items属于ItemCollection的集合类型,所以每一个Item里面都可以放入一个Object类型对象,这里有意思的地方就是,
如果我放入的是一个UI元素,那么很好,wpf会调用UI的OnRender方法将UI元素呈现,如果说是一个没有OnRender方法的元素,那该
怎么办呢?wpf很智能,它会创建一个TextBlock,然后调用该对象的ToString()将字符串呈现在TextBlock上。
ItemsSource:
从前面文章中我们也看到,ItemsSource常用于数据绑定,所以是一个非常实用的属性。

<1>Expander

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Expander Header="年龄组" Height="208" Margin="39,33,154,70" Name="expander1" Width="310">
<StackPanel>
<RadioButton Content="RadioButton1" Height="16" Name="radioButton1" />
<RadioButton Content="RadioButton2" Height="16" Name="radioButton2" />
</StackPanel>
</Expander>
</Grid>
</Window>

<2>GroupBox

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<GroupBox Header="年龄组" Height="208" Margin="39,33,154,70" Name="expander1" Width="310">
<StackPanel>
<RadioButton Content="RadioButton1" Height="16" Name="radioButton1" />
<RadioButton Content="RadioButton2" Height="16" Name="radioButton2" />
</StackPanel>
</GroupBox>
</Grid>
</Window>


<3>TabItem

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TabControl TabStripPlacement="Top" SelectedIndex="2">
<TabItem Header="TabItem1">
<TextBlock>111111</TextBlock>
</TabItem>
<TabItem Header="TabItem2">
<TextBlock>222222222</TextBlock>
</TabItem>
<TabItem Header="TabItem3">
<TextBlock>33333333</TextBlock>
</TabItem>
<TabItem Header="TabItem4">
<TextBlock>444444444</TextBlock>
</TabItem>
</TabControl> </Grid>
</Window>

3:文本控件

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="130,103,0,0" Name="button1" VerticalAlignment="Top" Width="75"
ToolTipService.HorizontalOffset="20"
ToolTipService.VerticalOffset="20" >
<Button.ToolTip>
<StackPanel>
<GroupBox Header="XXX选择题,你懂得...">
<GroupBox.Content>
<StackPanel>
<TextBlock x:Name="A">A:XXXX</TextBlock>
<TextBlock x:Name="B">B:XX</TextBlock>
<TextBlock x:Name="C">C:OOOO</TextBlock>
<TextBlock x:Name="D">D:OO</TextBlock>
</StackPanel>
</GroupBox.Content>
</GroupBox>
</StackPanel>
</Button.ToolTip>
</Button>
</Grid>
</Window>

4:范围控件

<1>ScrollViewer

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ScrollViewer Height="108" HorizontalAlignment="Left" Margin="98,63,0,0"
Name="scrollViewer1" VerticalAlignment="Top" Width="224"
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<StackPanel x:Name="Test" Orientation="Horizontal"> </StackPanel>
</ScrollViewer>
</Grid>
</Window>
namespace WpfApplication1
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
for (int i = ; i < ; i++)
{
TextBox tbx = new TextBox();
tbx.Text = i.ToString();
Test.Children.Add(tbx);
}
}
}
}

<2> ScrollBar

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid>
<StackPanel Height="100" Margin="97,61,206,150" Name="stackPanel1" Width="200">
<ScrollBar Name="test" Orientation="Horizontal" Maximum="100" Minimum="5" SmallChange="2" Height="17" Width="186" />
<Label Content="滑动块值"/>
<TextBox Name="txtScrollValue" Text="{Binding ElementName=test, Path=Value}"/>
</StackPanel>
</Grid>
</Grid>
</Window>

<3>ProgressBar

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ProgressBar Height="20" Margin="40" Name="ProgressBar1" IsIndeterminate="True"></ProgressBar>
</Grid>
</Window>

WPF控件的更多相关文章

  1. 浅尝辄止——使用ActiveX装载WPF控件

    1 引言 使用VC编写的容器类编辑器,很多都可以挂接ActiveX控件,因为基于COM的ActiveX控件不仅封装性不错,还可以显示一些不错的界面图元. 但是随着技术不断的进步,已被抛弃的Active ...

  2. XMAL语法系列之-(2)---WPF控件继承图

    WPF控件继承图 1 FrameworkElement 1.1 Panel(面板类元素) 1.1.1 Canvas 1.1.2 DockPanel 1.1.3 Grid 1.1.4 TabPanel ...

  3. 通过WinForm控件创建的WPF控件无法输入的问题

    今天把写的一个WPF程序发布到别的机器上执行,发现一个比较奇怪的问题:在那个机器上用英文输入法无法输入数字,非要切换到中文输入法才行:但在我的机器上却是好好的. 最开始以为是输入法的问题,弄了好一阵子 ...

  4. WPF控件--利用Winform库中的NotifyIcon实现托盘小程序

    WPF控件--NotifyIcon   运行界面如下所示:            图1                                             图2 代码很少,如下所示 ...

  5. (转)WPF控件开源资源

    (转)WPF控件开源资源 Textbox Drag/Drop in WPFhttp://www.codeproject.com/Articles/42696/Textbox-Drag-Drop-in- ...

  6. WPF控件模板

    引言:在进行WPF项目开发过程中,由于项目的需要,经常要对某个控件进行特殊的设定,其中就牵涉到模板的相关方面的内容.本文也是在自己进行项目开发过程中遇到控件模板设定时集中搜集资料后整理出来的,以供在以 ...

  7. 关于WinForm引用WPF窗体---在Winform窗体中使用WPF控件

    项目中有个界面展示用WPF实现起来比较简单,并且能提供更酷炫的效果,但是在WinForm中使用WPF窗体出现了问题,在网上找了一下有些人说Winform不能引用WPF的窗体,我就很纳闷,Win32都能 ...

  8. 我的WPF控件库——KAN.WPF.XCtrl(141105)

    自己开发的WPF控件库,只是初版,有扩展的Button,TextBox,Window.详细参见前几篇博文. WPF自定义控件(一)——Button:http://www.cnblogs.com/Qin ...

  9. Dev的WPF控件与VS2012不兼容问题

    在只有vs2010环境下Dev的wpf可以在视图模式下显示,但是安装vs2012后无法打开界面的视图模式,报错:无法创建控件实例! 发现是Dev的wpf控件与.net framework 4.5不兼容 ...

  10. 解决 CefSharp WPF控件不能使用输入法输入中文的问题(代码已提交到 github)

    首先,本文所有 代码已经提交到github,需要的可以直接从github获取:https://github.com/starts2000/CefSharp,希望可以帮助到有需要的朋友们. CEF 简介 ...

随机推荐

  1. [转载]JavaEE学习篇之——JQuery技术详解

    原文链接:http://blog.csdn.net/jiangwei0910410003/article/details/32102187 1.简介2.工具3.jQuery对象 1.DOM对象转化成j ...

  2. ACM - a + b Problem

    前几天看了ACM的第一题,映入眼帘的是一个“简单”的题目: 输入两个数,a,b 输出他们的和. 本着,此乃ACM的原则,便有了如下的思考: ACM的题目肯定很难,a+b,怎么可能直接printf,不行 ...

  3. Linux环境变量的添加设置

    以前一直都记着的,后来做的事情多了就什么都忘的差不多了. 在Linux中,环境变量一般添加有这么几个地方: 1./etc/profile 这个目录设置的变量为整个系统的全局变量,所有的用户通用,一般不 ...

  4. RPC(Remote Procedure Call Protocol)——远程过程调用协议 学习总结

        首先了解什么叫RPC,为什么要RPC,RPC是指远程过程调用,也就是说两台服务器A,B,一个应用部署在A服务器上,想要调用B服务器上应用提供的函数/方法,由于不在一个内存空间,不能直接调用,需 ...

  5. Struts2中的OGNL通配符

    <action name="*_*" class="action.{1}Action" method="{2}"> 匹配,第一个 ...

  6. IDEA 新建文件默认加入CVS

    是要先add,不过可以设置创建的文件都默认 add的.修改默认值看下图:打开系统设置,找到 Version Control 设置选项: 在 When files are created 选项中选择第二 ...

  7. 解决Python往MySQL插入中文时报错的问题

    今天遇到一个问题,用Python往MySQL插入数据时,若数据中包含中文会报类似下面的错误: ERROR 1366: Incorrect string value: '\xE4\xB8\xAD\xE5 ...

  8. neutron的基本原理

    neutron是openstack的一个重要模块,也是比较难以理解和debug的模块之一. 我这里安装如图安装了经典的三个节点的Havana的Openstack   图1 分三个网络: Externa ...

  9. POJ 1258

    http://poj.org/problem?id=1258 今天晚上随便找了两道题,没想到两道都是我第一次碰到的类型———最小生成树.我以前并没有见过,也不知道怎么做,然后就看书,思路很容易理解 但 ...

  10. hnu11187

    AC自动机+DP #include <cstdio> #include <queue> #include <cstring> using namespace std ...