WPF 自带控件札记
2009-10-23 17:22
92 查看
Contentcontrols
判断Contentcontrol是否有content:
使用HasContent属性
增加此属性,而不直接使用Content==null的原因是方便在xaml做出判断,比如可以根据HasContent增加Trigger
ContentControl的呈现:
调用UIElement的OnRender方法,如果content没此方法,会调用ToString方法
Button:
Button.IsDefault;Button.IsCancel
RepeatButton:
间隔性的触发click事件。Delay;Interval;默认值SystemParameters.KeyboardDelayandSystemParameters.KeyboardSpeed
ToggleButton&CheckBox:
IsThreeState标记是否三态。三态时第一次True,第二次null,第三次False
RadioButton:
同一parent里的RadioButton被分到同一组,或者指定GroupName属性(string类型),即使不同parent,在指定GroupName的情况下,也属于一组。
Label:
可在按下accesskey时,把焦点移到Label绑定的控件上。
<LabelTarget="{BindingElementName=userNameBox}">_UserName:Label>
<TextBoxName="userNameBox"/>
ToolTip:
FrameworkElement和FrameworkContentElement定义了ToolTrip属性。
ToolTip内容可以自定义,但是不能与之交互。
ToolTipService提供了一些attachedproperty,方便定义ToolTip的行为,如ToolTipService.ShowDuration等。
Frame:
与HTML中的Frame一样。Frame中的元素与Frame外的元素是不相干的,比如属性继承,对于Frame里的元素就不适用了。
ItemsControl
ListBox:
当绑定的是一个较复杂的对象时,可以用DisplayMemberPath来指定绑定的具体是该对象中哪个属性。
<Windowx:Class="WpfApplication1.Window2"
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"
Title="Window2"Height="300"Width="300">
<StackPanel>
<ListBoxDisplayMemberPath="DayOfWeek">
<Button>ButtonButton>
<ExpanderHeader="Expander"/>
<sys:DateTime>1/1/2007sys:DateTime>
<sys:DateTime>1/2/2007sys:DateTime>
<sys:DateTime>1/3/2007sys:DateTime>
ListBox>
StackPanel>
Window>
可以看到DateTimeB的显示都是正确的,而Button和Expander没有DayOfWeek属性,所以显示String.Empty
Combobox:
支持敲字母检索。有两个属性可以控制此功能,IsEditable和IsReadonly。
IsEditable为False时,Combobox样式和普通的Combobox一样,设置为True时,Combobox变为类TextBox的样式。
IsEditable为True,且IsReadonly为True时,虽然Combobox显示为TextBox样式,但是不能敲字符。
IsEditable为True,且IsReadonly为False时,可以输入任意字符。
如果Combobox里的Item是复杂的组合,要实现检索,用TextSearch的AttachedProperty。
…
因为Items结构会变化,可以把TextSearch.TextPath分摊到每个Item里。这是因为属性继承的原则。
横向排列ListBox:
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanelOrientation="Horizontal"/>
ItemsPanelTemplate>
ListBox.ItemsPanel>
ListBox>
FrameworkElementFactorypanelFactory=
newFrameworkElementFactory(typeof(VirtualizingStackPanel));
panelFactory.SetValue(VirtualizingStackPanel.OrientationProperty,
Orientation.Horizontal);
myListBox.ItemsPanel=newItemsPanelTemplate(panelFactory);
平滑滚动Listbox:
ScrollViewer.CanContentScroll
ListBox排序:
//Clearanyexistingsortingfirst
myItemsControl.Items.SortDescriptions.Clear();
//SortbytheContentproperty
myItemsControl.Items.SortDescriptions.Add(
newSortDescription(“Content”,ListSortDirection.Ascending));
ListView:
<ListView>
<ListView.View>
<GridView>
<GridViewColumnHeader="Date"/>
<GridViewColumnHeader="DayofWeek"
DisplayMemberBinding"{BindingDayOfWeek}"/>
<GridViewColumnHeader="Year"DisplayMemberBinding="{BindingYear}"/>
GridView>
ListView.View>
<sys:DateTime>1/1/2007sys:DateTime>
<sys:DateTime>1/2/2007sys:DateTime>
<sys:DateTime>1/3/2007sys:DateTime>
ListView>
GridView不支持排序,需要自己用SortDescriptions实现
ToolBar:
多个ToolBar可以放在ToolBarTray中。
RangeControls
ProgressBar:
IsIndeterminate:设为True时,显示为连续滚动
Orientation:方向,横竖
Slider:
TextandInkControls
TextBox:
允许多行:AcceptsReturn=True
自动换行:TextWrapping–>WraporWrapWithOverflow。Wrap不会截断字,WrapWithOverflow而截断。
拼写检查:SpellCheck.IsEnabled=True,这是个attachedproperty,可是不生效,不知道是不是和区域设置有关。
判断Contentcontrol是否有content:
使用HasContent属性
增加此属性,而不直接使用Content==null的原因是方便在xaml做出判断,比如可以根据HasContent增加Trigger
ContentControl的呈现:
调用UIElement的OnRender方法,如果content没此方法,会调用ToString方法
Button:
Button.IsDefault;Button.IsCancel
RepeatButton:
间隔性的触发click事件。Delay;Interval;默认值SystemParameters.KeyboardDelayandSystemParameters.KeyboardSpeed
ToggleButton&CheckBox:
IsThreeState标记是否三态。三态时第一次True,第二次null,第三次False
RadioButton:
同一parent里的RadioButton被分到同一组,或者指定GroupName属性(string类型),即使不同parent,在指定GroupName的情况下,也属于一组。
Label:
可在按下accesskey时,把焦点移到Label绑定的控件上。
<LabelTarget="{BindingElementName=userNameBox}">_UserName:Label>
<TextBoxName="userNameBox"/>
ToolTip:
FrameworkElement和FrameworkContentElement定义了ToolTrip属性。
ToolTip内容可以自定义,但是不能与之交互。
ToolTipService提供了一些attachedproperty,方便定义ToolTip的行为,如ToolTipService.ShowDuration等。
Frame:
与HTML中的Frame一样。Frame中的元素与Frame外的元素是不相干的,比如属性继承,对于Frame里的元素就不适用了。
ItemsControl
ListBox:
当绑定的是一个较复杂的对象时,可以用DisplayMemberPath来指定绑定的具体是该对象中哪个属性。
<Windowx:Class="WpfApplication1.Window2"
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"
Title="Window2"Height="300"Width="300">
<StackPanel>
<ListBoxDisplayMemberPath="DayOfWeek">
<Button>ButtonButton>
<ExpanderHeader="Expander"/>
<sys:DateTime>1/1/2007sys:DateTime>
<sys:DateTime>1/2/2007sys:DateTime>
<sys:DateTime>1/3/2007sys:DateTime>
ListBox>
StackPanel>
Window>
可以看到DateTimeB的显示都是正确的,而Button和Expander没有DayOfWeek属性,所以显示String.Empty
Combobox:
支持敲字母检索。有两个属性可以控制此功能,IsEditable和IsReadonly。
IsEditable为False时,Combobox样式和普通的Combobox一样,设置为True时,Combobox变为类TextBox的样式。
IsEditable为True,且IsReadonly为True时,虽然Combobox显示为TextBox样式,但是不能敲字符。
IsEditable为True,且IsReadonly为False时,可以输入任意字符。
如果Combobox里的Item是复杂的组合,要实现检索,用TextSearch的AttachedProperty。
…
因为Items结构会变化,可以把TextSearch.TextPath分摊到每个Item里。这是因为属性继承的原则。
横向排列ListBox:
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanelOrientation="Horizontal"/>
ItemsPanelTemplate>
ListBox.ItemsPanel>
ListBox>
FrameworkElementFactorypanelFactory=
newFrameworkElementFactory(typeof(VirtualizingStackPanel));
panelFactory.SetValue(VirtualizingStackPanel.OrientationProperty,
Orientation.Horizontal);
myListBox.ItemsPanel=newItemsPanelTemplate(panelFactory);
平滑滚动Listbox:
ScrollViewer.CanContentScroll
ListBox排序:
//Clearanyexistingsortingfirst
myItemsControl.Items.SortDescriptions.Clear();
//SortbytheContentproperty
myItemsControl.Items.SortDescriptions.Add(
newSortDescription(“Content”,ListSortDirection.Ascending));
ListView:
<ListView>
<ListView.View>
<GridView>
<GridViewColumnHeader="Date"/>
<GridViewColumnHeader="DayofWeek"
DisplayMemberBinding"{BindingDayOfWeek}"/>
<GridViewColumnHeader="Year"DisplayMemberBinding="{BindingYear}"/>
GridView>
ListView.View>
<sys:DateTime>1/1/2007sys:DateTime>
<sys:DateTime>1/2/2007sys:DateTime>
<sys:DateTime>1/3/2007sys:DateTime>
ListView>
GridView不支持排序,需要自己用SortDescriptions实现
ToolBar:
多个ToolBar可以放在ToolBarTray中。
RangeControls
ProgressBar:
IsIndeterminate:设为True时,显示为连续滚动
Orientation:方向,横竖
Slider:
TextandInkControls
TextBox:
允许多行:AcceptsReturn=True
自动换行:TextWrapping–>WraporWrapWithOverflow。Wrap不会截断字,WrapWithOverflow而截断。
拼写检查:SpellCheck.IsEnabled=True,这是个attachedproperty,可是不生效,不知道是不是和区域设置有关。
相关文章推荐
- WPF 自带控件札记
- wp8和wpf里监听控件自带属性的变化
- WPF 自带控件 总结之二
- WPF的DEV换肤 连WPF自带控件一起换肤
- VS自带WPF,Silverlight控件样式和模板
- C# 如何在winform中使用wpf用户控件
- WPF 自定义分页控件一
- C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(十五) 精灵控件横空出世!②
- (转)WPF控件开源资源
- C# Winform中自定义筛选及自带统计行的Datagridview控件
- 转载 [WPF][C#]在WPF中内嵌WindowsForm控件-使用WindowsFormsControlLibrary
- WPF和WindowsForm下的按下Enter跳转下一个控件通用方法
- WPF将控件保存为图片
- WPF ItemsControl 控件支持鼠标滚轮滑动
- 取消控件自带click事件及行选中事件
- 潜移默化学会WPF(技巧篇)--具有Items元素的控件子项获取(一)
- WPF 中获取DataGrid 模板列中控件的对像
- WPF DataPager控件
- 图像处理控件ImageGear for .NET教程:C# WPF应用程序创建示例(2)
- Infragistics控件使用札记