Content controls
判断Content control是否有content:
使用HasContent属性
增加此属性,而不直接使用Content == null 的原因是方便在xaml做出判断,比如可以根据HasContent增加Trigger
Content Control的呈现:
调用UIElement的OnRender方法,如果content没此方法,会调用ToString方法
Button:
Button.IsDefault; Button.IsCancel
RepeatButton:
间隔性的触发click事件。 Delay; Interval ; 默认值SystemParameters.KeyboardDelay and SystemParameters.KeyboardSpeed
ToggleButton & CheckBox:
IsThreeState标记是否三态。三态时第一次True,第二次null,第三次False
RadioButton:
同一parent里的RadioButton被分到同一组,或者指定GroupName属性(string类型),即使不同parent,在指定GroupName的情况下,也属于一组。
Label:
可在按下access key时,把焦点移到Label绑定的控件上。
<Label Target="{Binding ElementName=userNameBox}">_User Name:Label>
<TextBox Name="userNameBox"/>
ToolTip:
FrameworkElement和FrameworkContentElement定义了ToolTrip属性。
ToolTip内容可以自定义,但是不能与之交互。
ToolTipService提供了一些attached property,方便定义ToolTip的行为,如ToolTipService.ShowDuration等。
Frame:
与HTML中的Frame一样。Frame中的元素与Frame外的元素是不相干的,比如属性继承,对于Frame里的元素就不适用了。
Items Control
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>
<ListBox DisplayMemberPath="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的Attached Property。
…
因为Items结构会变化,可以把TextSearch.TextPath分摊到每个Item里。这是因为属性继承的原则。
横向排列ListBox:
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
ItemsPanelTemplate>
ListBox.ItemsPanel>
ListBox>
FrameworkElementFactory panelFactory =
new FrameworkElementFactory(typeof(VirtualizingStackPanel));
panelFactory.SetValue(VirtualizingStackPanel.OrientationProperty,
Orientation.Horizontal);
myListBox.ItemsPanel = new ItemsPanelTemplate(panelFactory);
平滑滚动Listbox:
ScrollViewer.CanContentScroll
ListBox排序:
// Clear any existing sorting first
myItemsControl.Items.SortDescriptions.Clear();
// Sort by the Content property
myItemsControl.Items.SortDescriptions.Add(
new SortDescription(“Content”, ListSortDirection.Ascending));
ListView:
<ListView>
<ListView.View>
<GridView>
<GridViewColumn Header="Date"/>
<GridViewColumn Header="Day of Week"
DisplayMemberBinding"{Binding DayOfWeek}"/>
<GridViewColumn Header="Year" DisplayMemberBinding="{Binding Year}"/>
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中。
Range Controls
ProgressBar:
IsIndeterminate:设为True时,显示为连续滚动
Orientation:方向,横竖
Slider:
Text and Ink Controls
TextBox:
允许多行:AcceptsReturn = True
自动换行:TextWrapping –>Wrap or WrapWithOverflow。 Wrap不会截断字,WrapWithOverflow而截断。
拼写检查:SpellCheck.IsEnabled = True, 这是个attached property,可是不生效,不知道是不是和区域设置有关。