時(shí)間:2023-07-24 06:39:01 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-07-24 06:39:01 來(lái)源:網(wǎng)站運(yùn)營(yíng)
用XAML做網(wǎng)頁(yè)?。 蚣埽?br> <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowTitle="MailMail" FontFamily="微軟雅黑" Background="#FF424242" SnapsToDevicePixels="True"></Page>
WindowTitle就是頁(yè)面標(biāo)題。 <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"></ScrollViewer>
把橫向和縱向滾動(dòng)條的顯示屬性都設(shè)為Auto是個(gè)比較好的方案,這樣在不需要的時(shí)候就會(huì)自動(dòng)隱藏了。 <Grid MinHeight="900" MinWidth="1000"> <Grid.ColumnDefinitions> <ColumnDefinition Width="8*"/> <ColumnDefinition Width="84*"/> <ColumnDefinition Width="8*"/> </Grid.ColumnDefinitions> </Grid>
其中定義了三個(gè)列,兩邊8%留作空白,中間84%是頁(yè)面主體。 <DockPanel Background="#FFF" Grid.Column="1"></DockPanel>
DockPanel中裝載的就是頁(yè)面的各個(gè)區(qū)塊了: <DockPanel x:Name="Head" DockPanel.Dock="Top" Background="#FF4A4A4A" Height="115"></DockPanel> <Border x:Name="HeadLine" Background="#888" BorderThickness="0,1" DockPanel.Dock="Top" Height="15"></Border> <Grid x:Name="Show" Background="#EEE" DockPanel.Dock="Top" Height="135" ClipToBounds="True"></Grid> <Border x:Name="Channel" DockPanel.Dock="Top" Height="50" Background="#FF8E45" BorderThickness="0,1,0,0" BorderBrush="#FFF"></Border> <Border x:Name="Footer" Background="#666" BorderBrush="#888" BorderThickness="0,4,0,0" DockPanel.Dock="Bottom" Height="55"></Border> <DockPanel x:Name="Body" Background="#FFFFFCD1"></DockPanel>
僅僅通過(guò)DockPanel.Dock屬性就可以將各個(gè)區(qū)塊完美的放置到它所應(yīng)處的位置,實(shí)際應(yīng)用中可以比這復(fù)雜很多,但實(shí)現(xiàn)起來(lái)依然是非常簡(jiǎn)單。 <DockPanel x:Name="Side" Background="#1E874900" DockPanel.Dock="Right" Width="245"></DockPanel> <StackPanel x:Name="Content"></StackPanel>
其實(shí)不用Body,直接把這兩個(gè)元素放在上層使用也沒(méi)有問(wèn)題,我在這里是希望它們有一個(gè)共同的背景才這樣設(shè)計(jì)的。 <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowTitle="MailMail" FontFamily="微軟雅黑" Background="#FF424242" SnapsToDevicePixels="True"> <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <Grid MinHeight="900" MinWidth="1000"> <Grid.ColumnDefinitions> <ColumnDefinition Width="8*"/> <ColumnDefinition Width="84*"/> <ColumnDefinition Width="8*"/> </Grid.ColumnDefinitions> <DockPanel Background="#FFF" Grid.Column="1"> <DockPanel x:Name="Head" DockPanel.Dock="Top" Background="#FF4A4A4A" Height="115"></DockPanel> <Border x:Name="HeadLine" Background="#888" BorderThickness="0,1" DockPanel.Dock="Top" Height="15"></Border> <Grid x:Name="Show" Background="#EEE" DockPanel.Dock="Top" Height="135" ClipToBounds="True"></Grid> <Border x:Name="Channel" DockPanel.Dock="Top" Height="50" Background="#FF8E45" BorderThickness="0,1,0,0" BorderBrush="#FFF"></Border> <Border x:Name="Footer" Background="#666" BorderBrush="#888" BorderThickness="0,4,0,0" DockPanel.Dock="Bottom" Height="55"></Border> <DockPanel x:Name="Body" Background="#FFFFFCD1"> <DockPanel x:Name="Side" DockPanel.Dock="Right" Width="245"></DockPanel> <StackPanel x:Name="Content"></StackPanel> </DockPanel> </DockPanel> </Grid> </ScrollViewer></Page>
它現(xiàn)在只包含了頁(yè)面的框架結(jié)構(gòu)和一點(diǎn)簡(jiǎn)單的樣式。 <?xml version="1.0" encoding="utf-8"?><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><DrawingBrush x:Key="back" Stretch="Uniform"><DrawingBrush.Drawing><DrawingGroup ClipGeometry="F1 M 0,0L 395.017,0L 395.017,466L 0,466L 0,0"><DrawingGroup.Children><GeometryDrawing Geometry="F1 M 64,5.5L 331.017,5.5"><GeometryDrawing.Pen><Pen Thickness="11" LineJoin="Round" Brush="#08000000"/></GeometryDrawing.Pen></GeometryDrawing><GeometryDrawing Geometry="F1 M 64,122.5L 331.017,122.5"><GeometryDrawing.Pen><Pen Thickness="128" LineJoin="Round" Brush="#06000000"/></GeometryDrawing.Pen></GeometryDrawing><GeometryDrawing Geometry="F1 M 64,428.501L 331.017,428.501"><GeometryDrawing.Pen><Pen Thickness="75" LineJoin="Round" Brush="#06000000"/></GeometryDrawing.Pen></GeometryDrawing><GeometryDrawing Geometry="F1 M 64,275.5L 331.017,275.5"><GeometryDrawing.Pen><Pen Thickness="35" LineJoin="Round" Brush="#0B000000"/></GeometryDrawing.Pen></GeometryDrawing></DrawingGroup.Children></DrawingGroup></DrawingBrush.Drawing></DrawingBrush></ResourceDictionary>
我們需要給“<DrawingBrush x:Key="back" Stretch="Uniform">”中加入幾個(gè)屬性:ViewportUnits="Absolute" Viewport="0,0,55,145" TileMode="FlipXY"
這些屬性控制了圖像的填充方式。 <Page.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="back.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Page.Resources>
然后為Grid加入背景屬性設(shè)置: <Grid MinHeight="900" MinWidth="1000" Background="{StaticResource back}">
這樣就完成了頁(yè)面背景樣式的設(shè)置。 <Rectangle Width="20" Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,0,0"> <Rectangle.Fill> <LinearGradientBrush StartPoint="1,0" EndPoint="0,0"> <GradientStop Color="#00000000" Offset="1" /> <GradientStop Color="#20000000" Offset="0" /> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Rectangle Width="20" Grid.Column="3" HorizontalAlignment="Left" Margin="0,0,0,0"> <Rectangle.Fill> <LinearGradientBrush StartPoint="1,0" EndPoint="0,0"> <GradientStop Color="#00000000" Offset="0" /> <GradientStop Color="#20000000" Offset="1" /> </LinearGradientBrush> </Rectangle.Fill> </Rectangle>
下面兩圖分別是設(shè)計(jì)效果和實(shí)際效果: <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowTitle="MailMail" FontFamily="微軟雅黑" Background="#FF424242" SnapsToDevicePixels="True"> <Page.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="back.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Page.Resources> <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <Grid MinHeight="900" MinWidth="1000" Background="{StaticResource back}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="8*"/> <ColumnDefinition Width="84*"/> <ColumnDefinition Width="8*"/> </Grid.ColumnDefinitions> <Rectangle Width="20" Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,0,0"> <Rectangle.Fill> <LinearGradientBrush StartPoint="1,0" EndPoint="0,0"> <GradientStop Color="#00000000" Offset="1" /> <GradientStop Color="#20000000" Offset="0" /> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Rectangle Width="20" Grid.Column="3" HorizontalAlignment="Left" Margin="0,0,0,0"> <Rectangle.Fill> <LinearGradientBrush StartPoint="1,0" EndPoint="0,0"> <GradientStop Color="#00000000" Offset="0" /> <GradientStop Color="#20000000" Offset="1" /> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <DockPanel Background="#FFF" Grid.Column="1"> <DockPanel x:Name="Head" DockPanel.Dock="Top" Background="#FF4A4A4A" Height="115"></DockPanel> <Border x:Name="HeadLine" Background="#888" BorderThickness="0,1" DockPanel.Dock="Top" Height="15"></Border> <Grid x:Name="Show" Background="#EEE" DockPanel.Dock="Top" Height="135" ClipToBounds="True"></Grid> <Border x:Name="Channel" DockPanel.Dock="Top" Height="50" Background="#FF8E45" BorderThickness="0,1,0,0" BorderBrush="#FFF"></Border> <Border x:Name="Footer" Background="#666" BorderBrush="#888" BorderThickness="0,4,0,0" DockPanel.Dock="Bottom" Height="55"></Border> <DockPanel x:Name="Body" Background="#FFFFFCD1"> <DockPanel x:Name="Side" Background="#1E874900" DockPanel.Dock="Right" Width="245"></DockPanel> <StackPanel x:Name="Content"></StackPanel> </DockPanel> </DockPanel> </Grid> </ScrollViewer></Page>
本篇至此結(jié)束,在后續(xù)的篇章中將繼續(xù)講解頁(yè)面主體中各個(gè)區(qū)塊的制作。關(guān)鍵詞:
客戶&案例
營(yíng)銷資訊
關(guān)于我們
客戶&案例
營(yíng)銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。