XAML代码:
// DemoViewer.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="BrawDraw.Com.Graphics.DemoViewer"
Title="Drawing with Shapes">
<DockPanel>
<TabControl Background="White">
<TabItem Header="Path">
<Frame Background="White" Source="PathExample.xaml" />
</TabItem>
<TabItem Header="Polygon">
<Frame Background="White" Source="PolygonExample.xaml" />
</TabItem>
<TabItem Header="Polyline">
<Frame Background="White" Source="PolylineExample.xaml" />
</TabItem>
<TabItem Header="Rectangle">
<Frame Background="White" Source="RectangleExample.xaml" />
</TabItem>
</TabControl>
</DockPanel>
</Window>
这里使用了TabControl控件,每个选项卡使用TabItem, 然后再在其中的Frame标签中使用Source属性指定嵌入的Page页面。
相应的选项卡代码示例(为方便说明,仅举两例):
(1)PolylineExample.xaml及C#代码:
详见: http://blog.csdn.net/johnsuna/archive/2007/10/19/1832994.aspx
(2)PathExample.xaml:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="BrawDraw.Com.Graphics.PathExample"
WindowTitle="Path Example">
<StackPanel>
<Border>
<Border.Background>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#CCCCFF" Offset="0" />
<GradientStop Color="AliceBlue" Offset="0.25" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<TextBlock Margin="10" HorizontalAlignment="Left">
Path Examples
</TextBlock>
</Border>
<StackPanel Margin="10">
<Border Style="{StaticResource MyGridBorderStyle}">
<Canvas Height="400" Width="400">
<Path
Data="M30,100 C 100,0 200,300 300,200 z"
Fill="Blue"
Stroke="Black"
StrokeThickness="4" />
</Canvas>
</Border>
</StackPanel>
</StackPanel>
</Page>
C#代码:
// PathExample.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace Microsoft.Samples.Graphics
{
public partial class PathExample : Page
{
public PathExample()
{
InitializeComponent();
}
}
}
这里,选项卡的具体内容从Page继承(使用Page作为顶级标签)。