您的位置:首页 > 其它

WPF小结(一&二) 布局和控件

2016-04-13 10:03 309 查看
从个人整理小结的角度出发,现在水平有限,部分结论是错的。就xmal文件来说,结构有三,命名空间、资源、主窗口。

一、 XMAL 命名空间

二、布局和控件(窗口的主架)

1.布局:

(1) Grid 网格布局 等比宽高度可以用来页面自适应。

(2) StackPanel 的Orientation控制方向,HorizontalAlignment控制水平布局,VerticalAlignment控制垂直布局。

StackPanel 留心<StackPanel><ListBox/></StackPanel> listbox 不出滚动条

(3) DockPanel DockPanel.Dock & LastChildFill属性 very cool.

(4) WrapPanel 自动换行 也挺溜

2.控件

控件分两种单个控件(如button textblock等)和列表控件(如listbox等)

(1)觉得比较酷的控件 WebBrowser、MediaElement、Thumb、Inkcanvas & listbox

(2)列表控件 结合ItemsPanelTemplate改写listbox container的style,Item的style 可以重写Template属性,DatatTemplate控制数据 。

<!--ListBox WrapPanel Style-->
<ItemsPanelTemplate x:Key="ItemsWrapPanelStyle">
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
<!--ListBoxItem Score Style-->
<Style TargetType="ListBoxItem" x:Key="ListBoxItemScoreStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Bd" BorderThickness="0" Margin="5" Background="AliceBlue">
<ContentPresenter/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" TargetName="Bd" Value="Blue"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="False"/>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="Yellow"/>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ListBox ItemsPanel="{StaticResource ItemsWrapPanelStyle}" ItemContainerStyle="{StaticResource ListBoxItemScoreStyle}">
<ListBoxItem>
ListBox
</ListBoxItem>
<ListBoxItem>
好棒
</ListBoxItem>
</ListBox>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: