Fork me on GitHub

Frame

 

Fram是一个框架控件,它可能用来呈现网页和xaml文件,如下面的便子,第一个按钮能转到一个网页中,第二个按钮能转到相应的xaml文件中,关且这个xaml不是以代码形式表现,而是以图形形式表现。当调用xaml时要引用一个参数UriKind.RelativeOrAbsolute

XAML代码

<Page

       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

       xmlns:d="http://schemas.microsoft.com/expression/blend/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"

       x:Class="Controls.FrameTest"

       x:Name="Page"

       WindowTitle="Page"

       FlowDirection="LeftToRight"

       Width="640" Height="480"

       WindowWidth="640" WindowHeight="480">

 

       <Grid x:Name="LayoutRoot">

              <Grid HorizontalAlignment="Stretch" Margin="1,1,1,1" VerticalAlignment="Stretch">

                     <Grid.RowDefinitions>

                            <RowDefinition Height="Auto" MinHeight="21.1196666666667"/>

                            <RowDefinition Height="Auto" MinHeight="458.88"/>

                     </Grid.RowDefinitions>

                     <Frame HorizontalAlignment="Stretch" Margin="0,24.277,0,0" x:Name="myFrame" VerticalAlignment="Stretch" Content="" Grid.RowSpan="2"/>

                     <TextBox x:Name="text" Text="http:\\www.baidu.com" TextWrapping="Wrap" d:LayoutOverrides="VerticalAlignment" HorizontalAlignment="Left" VerticalAlignment="Top" Width="449.873" Height="20.277"/>

                     <Button Click="BrowseAHomePage" Width="74.127" Height="20.277" Content="GO Web Sit" RenderTransformOrigin="-1.305,-1.48" HorizontalAlignment="Right" Margin="0,0,110,0.843" VerticalAlignment="Bottom"/>

                     <Button Click="BrowseAHomePage1" Width="74.127" Content="xaml" RenderTransformOrigin="-1.305,-1.48" HorizontalAlignment="Right" Margin="0,0,31.873,0.843"/>

              </Grid>

   </Grid>

</Page>

 

CS代码

      private void BrowseAHomePage(object sender, RoutedEventArgs e)

        {                    

                myFrame.Navigate(new System.Uri(text.Text));                

        }

        private void BrowseAHomePage1(object sender, RoutedEventArgs e)

        {

            myFrame.Navigate(new System.Uri("FrameTest.xaml", UriKind.RelativeOrAbsolute));

        }

效果如下,先点击“xaml”,后点击“GO Web Sit


本文参考MSDN组织。
posted @ 2007-03-24 23:33  桂素伟  阅读(511)  评论(0编辑  收藏  举报