您的位置:首页 > 其它

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,可是不生效,不知道是不是和区域设置有关。


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: