Xaml frame on a Tab

image_pdfimage_print


   
       
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Microsoft.Samples.Graphics.UsingVisualBrush.SampleViewer"
    Title="VisualBrush Sample">

  <DockPanel Background="White">
  
    <TabControl Name="sampleSelector" Background="White" BorderBrush="Orange">

      <TabItem Header="Painting with Visuals" >
        <Frame Source="PaintingWithVisuals.xaml" Background="White" />            
      </TabItem>
      <TabItem Header="Magnifying Glass Example" >
        <Frame Source="MagnifyingGlassExample.xaml" Background="White" />            
      </TabItem>     
      <TabItem Header="Reflection Example" >
        <Frame Source="ReflectionExample.xaml" Background="White" />            
      </TabItem>       
    </TabControl> 
  </DockPanel>


</Window>

   
    
    
    
    
    
    
     


Use a Frame control to navigate to Web pages and a Extensible Application Markup Language (XAML) page.

image_pdfimage_print


   
  


<Page x:Class="FrameExample.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <StackPanel>
        <RadioButton Name="VisualBasic" Checked="BrowseAHomePage" GroupName="HomePages">
      Visual Basic
        </RadioButton>
        <RadioButton Name="VisualCSharp" Checked="BrowseAHomePage" GroupName="HomePages">
      Visual C# 
        </RadioButton>
        <RadioButton Name="AnotherPage" Checked="BrowseAHomePage" GroupName="HomePages">
      XAML Page
        </RadioButton>
        <Frame Name = "myFrame" Background="LightBlue"/>
    </StackPanel>
</Page>

//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Input;
using System.IO;
using System.Net;

namespace FrameExample
{
  public partial class Page1 : Page
  {
    private void BrowseAHomePage(object sender, RoutedEventArgs e)
    {
      if ((Boolean)VisualBasic.IsChecked)
        myFrame.Navigate(new System.Uri("http://msdn.microsoft.com/vbasic/")); 
      else if ((Boolean)VisualCSharp.IsChecked)
        myFrame.Navigate(new System.Uri("http://msdn.microsoft.com/vcsharp/")); 
      else if ((Boolean)AnotherPage.IsChecked)
        myFrame.Navigate(new System.Uri("AnotherPage.xaml",UriKind.RelativeOrAbsolute));
     }
  }
}

   
    
     


Put a Frame tag onto a Window to host a page

image_pdfimage_print
   
  

<Window x:Class="WindowPageHost.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     Title="WindowWithFrame" Height="300" Width="392"
    >
    <Grid Margin="3">
      <Grid.ColumnDefinitions>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
      </Grid.ColumnDefinitions>

      <StackPanel>
        <Button Margin="3" Padding="3" Click="cmdClose_Click">Close</Button>
      </StackPanel>
      <Frame Grid.Column="1" Source="Page1.xaml" BorderBrush="Blue" BorderThickness="1"></Frame>
    </Grid>
  
</Window>


//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace WindowPageHost
{

    public partial class Window1 : System.Windows.Window
    {

        public Window1()
        {
            InitializeComponent();
        }
        private void cmdClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}

   
    
     


Navigate Frame to a xaml document

image_pdfimage_print
   
  

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="FrameWindowSample.SDKViewerWindow"
    Title="SDK Viewer" Width="430" Height="400">
    <StackPanel Margin="10,10,10,10">
        <TextBlock>
            <Hyperlink Name="homeHyperlink" Click="homeHyperlink_Click">Home</Hyperlink>
        </TextBlock>
        <Frame Name="sdkFrame" Background="WhiteSmoke" Source="SDKFramePage.xaml" NavigationUIVisibility="Visible" />
       
    </StackPanel>
</Window>

//File:Window.xaml.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace FrameWindowSample
{
    public partial class SDKViewerWindow : Window
    {

        public SDKViewerWindow()
        {
            InitializeComponent();
        }
        
        void homeHyperlink_Click(object sender, RoutedEventArgs e) {
            this.sdkFrame.Navigate(new Uri("SDKFramePage.xaml", UriKind.Relative));
        }

    }
}

   
    
     


Navigate Frame to a URL

image_pdfimage_print


   
  


<Window x:Class="TreeViewDataBinding.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TreeViewDataBinding"
    xmlns:EngNews="clr-namespace:TreeViewDataBinding">

  <Window.Resources>
    <ObjectDataProvider x:Key="EasternHemisphereDataSource" ObjectType="{x:Type EngNews:WebSiteGroupA}"/>
    <ObjectDataProvider x:Key="WesternHemisphereDataSource" ObjectType="{x:Type EngNews:WebSiteGroupB}"/>
    <DataTemplate x:Key="NewspaperTVItem">
      <DockPanel>
        <Image Source="c:image.jpg"/>
        <TextBlock VerticalAlignment="center" Text ="{Binding Path=Name}"/>
      </DockPanel>
    </DataTemplate>
    <DataTemplate x:Key="WesternHemisphereHeaderTemplate">
      <DockPanel>
        <Ellipse Width="7" Height="7"  Fill="Blue" DockPanel.Dock="Left"/>
        <TextBlock Margin="2,0,0,0" VerticalAlignment="Center" DockPanel.Dock="Right">
          test
        </TextBlock>
      </DockPanel>
    </DataTemplate>
    <DataTemplate x:Key="EasternHemisphereHeaderTemplate">
      <DockPanel>
        <Ellipse Width="7" Height="7"  Fill="Blue" DockPanel.Dock="Left"/>
        <TextBlock DockPanel.Dock="Right">Eastern Hemisphere</TextBlock>
      </DockPanel>
    </DataTemplate>
  </Window.Resources>
  <StackPanel>
      <TreeView Name="WebSiteEntrys" SelectedItemChanged="SelectedNewspaperChanged">
        <TreeViewItem HeaderTemplate="{StaticResource WesternHemisphereHeaderTemplate}" 
                      ItemsSource="{Binding Source={StaticResource WesternHemisphereDataSource}}"
                      ItemTemplate="{StaticResource NewspaperTVItem}"/>
        <TreeViewItem HeaderTemplate="{StaticResource EasternHemisphereHeaderTemplate}"
                      ItemsSource="{Binding Source={StaticResource EasternHemisphereDataSource}}"
                      ItemTemplate="{StaticResource NewspaperTVItem}"/>
      </TreeView>
      <Frame Name = "NewspaperFrame" Content="this is a test."/>
  </StackPanel>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace TreeViewDataBinding
{
    public partial class Window1 : Window{
        public Window1(){
            InitializeComponent();
        }
        private void SelectedNewspaperChanged(object sender,RoutedPropertyChangedEventArgs<Object> e){
            WebSiteEntry engnews = WebSiteEntrys.SelectedItem as WebSiteEntry;
            if( engnews != null ) NewspaperFrame.Navigate(new System.Uri(engnews.Website));
        }
    }
    public class WebSiteEntry{
        private string _name;
        private string _website;

        public string Website
        {
            get { return _website; }
            set { _website = value; }
        }

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public WebSiteEntry(string name, string website)
        {
            Name = name;
            Website = website;
        }
    }
    public class WebSiteGroupA : ObservableCollection<WebSiteEntry>
    {
        public WebSiteGroupA()
        {
            Add(new WebSiteEntry("A","http://www.A.com"));
            Add(new WebSiteEntry("B","http://www.B.com"));
            Add(new WebSiteEntry("C","http://www.C.com"));
        }
    }

    public class WebSiteGroupB : ObservableCollection<WebSiteEntry>
    {
        public WebSiteGroupB()
        {
            Add(new WebSiteEntry("D","http://www.D.com/"));
            Add(new WebSiteEntry("E","http://www.E.net/"));
            Add(new WebSiteEntry("F","http://www.F.com"));
        }
    }
}

   
    
     


LineGeometry

image_pdfimage_print


   
    

<Window x:Class="Workspace.DockExample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Workspace" Width="640" Height="480">
          <Path Stroke="Black" StrokeThickness="1">
            <Path.Data>
              <LineGeometry StartPoint="10,10" EndPoint="50,30" />
            </Path.Data>
          </Path>

</Window>

   
    
    
    
     


EllipseGeometry

image_pdfimage_print
   
    

<Window x:Class="Workspace.DockExample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Workspace" Width="640" Height="480">
          <Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
            <Path.Data>
              <EllipseGeometry Center="40,70" RadiusX="30" RadiusY="30" />
            </Path.Data>
          </Path>

</Window>