新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
WPF分割條應用要點解析
在WPF窗口布局中,我們經(jīng)常要用到窗口的分割,這篇文章主要是介紹怎樣用GridSpliter分割窗口。GridSpliter主要是用在布局控件GRID中,指定要分割的位置,第幾行,第幾列就可以實現(xiàn)格子的分割了。#t#

網(wǎng)站建設哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、微信小程序定制開發(fā)、集團企業(yè)網(wǎng)站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了鶴峰免費建站歡迎大家使用!
既然要做到劃分總個窗體,我們需要把格子的高和寬同窗口的實際高和寬綁定在一起,以此來實現(xiàn)總個窗體的分割。
以下是用XAML寫的一段WPF分割條代碼:
- < Page
- xmlns="http://schemas.microsoft
.com/winfx/2006/xaml/presentation" - xmlns:sys="clr-namespace:System;
assembly=mscorlib" - xmlns:x="http://schemas.microsoft.
com/winfx/2006/xaml" Name ="myWnd"> - < Page.Resources>
- < Style TargetType ="{x:Type Border}">
- < Setter Property ="BorderThickness"
Value ="1"/> - < Setter Property ="BorderBrush"
Value ="Black"/> - < /Style>
- < /Page.Resources>
- < !--首先,我們綁定格子的高和寬同窗口一樣大-->
- < Grid Background="White"
- Width ="{Binding Path=ActualWidth ,
ElementName=myWnd}" - Height="{Binding Path=ActualHeight ,
ElementName=myWnd}" - HorizontalAlignment="Left"
- VerticalAlignment="Top"
- ShowGridLines="False">
- < Grid.RowDefinitions>
- < RowDefinition Height="*" />
- < !--因為WPF分割條也是對象,要占用一行-->
- < RowDefinition Height="Auto" />
- < RowDefinition Height="*" />
- < /Grid.RowDefinitions>
- < Grid.ColumnDefinitions>
- < ColumnDefinition Width="*" />
- < !--因為分割條也是對象,要占用一列-->
- < ColumnDefinition Width="Auto" />
- < ColumnDefinition Width="*" />
- < /Grid.ColumnDefinitions>
- < Border Grid.Column="0" Grid.Row="0" />
- < Border Grid.Column="0" Grid.Row="2" />
- < Border Grid.Column="2" Grid.Row="0" />
- < Border Grid.Column="2" Grid.Row="2" />
- < !--此處GridSplitter 要占用三列-->
- < GridSplitter Grid.Row="1"
Grid.Column="0" Grid.ColumnSpan="3" - HorizontalAlignment="Stretch"
- VerticalAlignment="Center"
- Height="1"
- />
- < !--此處GridSplitter 要占用三行-->
- < GridSplitter Grid.Row="0"
Grid.Column="1" Grid.RowSpan="3" - HorizontalAlignment="Center"
- VerticalAlignment="Stretch"
- Width="1"
- />
- < /Grid>
- < /Page>
WPF分割條使用注意:豎直分割與水平分割時一定要區(qū)分HorizontalAlignment,VerticalAlignment的設置。
當前標題:WPF分割條應用要點解析
本文鏈接:http://m.5511xx.com/article/dhocods.html


咨詢
建站咨詢
