Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » WPF » Working with the frame object

Working with the frame object

In this article, I will represent the frame object witch is a container control that enables to navigate through internet and display some contents such as an Html page.

Author Rank:
Total page views :  2904
Total downloads :  44
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
Bejaoui.zip
 
Become a Sponsor


In this article, I will represent the frame object witch is a container control that enables to navigate through internet and display some contents such as an Html page. Normally, it is hosted within other elements such a Grid controls, tab Controls and so forth.

The sequence of events that are raised when a navigation action is performed are represented in the following diagram



Figure 1

Now, I will represent some of the frame most important members

Member

Description

Source-property It represents the current URI used to navigate, it is necessary to create a new URI object and overload its constructor by the URI string:
oFrame = new Frame();
oFrame.Source= new Uri( @"http://www.tunisianproducts.com/", UriKind.RelativeOrAbsolute);
CurrentSource-property This property gets the current used source, indeed this property couldn't be used directly using XAML. It is only used within a C# code context
Content-property This property enables get or set a contained object
Navigate-method It has three overloaded instances, the first one is Navigate(object) it enables Navigate asynchronously to content that is contained by an object, the second one is Navigate(uri) it Navigates asynchronously to content that is specified by a uniform resource identifier. Then the third is Navigate(object,object) it enables Navigate asynchronously to content that is contained by an object, and passes an object that contains data to be used for processing during navigation. Finally the Navigate(uri, object) that enables Navigate asynchronously to source content located at a uniform resource identifier (URI), and passes an object that contains data to be used for processing during navigation.
GoForward-method  It enables go to the most recent item located in the forward navigation history
 
GoBack-method  It enables go to the most recent item located in the previous navigation history
NavigationUIVisibility-property  As the frame provides a user interface that enables navigate forward and back. This user interface could be displayed or not according to this property state. To render this user interface visible then oFrame.NavigationUIVisibility = System.Windows.NavigationUIVisibility.Visible;
JournalOwnership-property  This is very important property witch determines if the frame will manage its own navigation history or it will be leaved to the parent navigator such as a Navigation Window object. To enable the frame manage its navigation history then
oFrame.JournalOwnership = System.Windows.Navigation.JournalOwnership.OwnsJournal;
else if the parent is preferred to do this then
oFrame.JournalOwnership = System.Windows.Navigation.JournalOwnership.UsesParentJournal;
Else, the Automatic alternative is used to indicate that the journal ownership depends on the type of parent.
oFrame.JournalOwnership = System.Windows.Navigation.JournalOwnership.Automatic;

Those are the most important properties according to the frame object.

To more understand the frame object in practice, I provide this example that consists of creating a primitive browser witch is developed by following those steps.

  1.  First, create a new WPF application
     
  2.  Copy and paste the bellow XAML code in the XAML code editor
      

    <Window x:Class="myWpfApplication.Window1"

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

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

        Title="Window1" Margin="0,0,0,0" Loaded="Window_Loaded" Height="720" Width="1060">

        <Grid Name="myGrid">

            <Grid.RowDefinitions>

                <RowDefinition Height="72*" />

                <RowDefinition Height="40*" />

                <RowDefinition Height="569*" />

                <RowDefinition Height="31*" />

            </Grid.RowDefinitions>

            <Menu Grid.Row="0" Name="myMenu" Height="24" VerticalAlignment="Top">

                <MenuItem Header="File">

                    <MenuItem Name="NewWindow" Header="New window" Click="NewWindow_Click"/>

                    <MenuItem Name="NewTab" Header="New tab" Click="NewTab_Click"/>

                    <MenuItem Name="OpenFile" Header="Open file" Click="OpenFile_Click"/>

                    <MenuItem Name="Quit" Header="Quit" Click="Quit_Click"/>

                </MenuItem>

            </Menu>

            <TextBox Grid.Row="1"  Name="textBox1" Margin="0,4.202,0,0" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left" Width="1109" />

            <Button Grid.Row="1" HorizontalAlignment="Right" Margin="0,4.202,0,0" Name="button1" Width="65" Height="26" VerticalAlignment="Top">Browse</Button>

            <StatusBar Grid.Row="3" Name="statusBar1" />

            <TabControl Grid.Row="2" Name="tabControl1" />

        </Grid>

       

    </Window>
     

  3. Switch to the design mode to see the presentation that will be as follow:



    Figure 2

    As you remark, the browser is formed by a menu, a navigation bar, a tab control that will host the frames objects and  finally a status bar bellow that displays the last navigated Uri.
     

  4. In the other hand, implement this code in the code behind zone.
     

    namespace myWpfApplication

    {

        /// <summary>

        /// Primitiv browser sample

        /// </summary>

        public partial class Window1 : Window

        {

            public Window1()

            {

                InitializeComponent();

            }

            /* oTabItem is a tab item that belongs to the multi tab control

             witch is the logical parent of the frames used to browse through

             internet*/

            TabItem oTabItem;

            /* The frame is the object used to browse through internet

             */

            Frame oFrame;

            /* The oLabel is used to display the current Uri*/

            Label oLabel;

            /*This is used as index for the new created tab items*/

            int i = 1;

            private void Window_Loaded(object sender, RoutedEventArgs e)

            {

                //Set the default value of the browser text

                textBox1.Text = "http://";

     

                //This will set the bacground of the browser

                System.Windows.Media.LinearGradientBrush oBrush;

                oBrush = new LinearGradientBrush(System.Windows.Media.Colors.Red, System.Windows.Media.Colors.Cornsilk, 40);

                this.Background = oBrush;

                myMenu.Background = System.Windows.Media.Brushes.RosyBrown;

                //Instanciate a new tabl item

                oTabItem = new TabItem();

                oTabItem.Header = "Tab0";

                tabControl1.Items.Add(oTabItem);

                //Instanciate a new frame object

                oFrame = new Frame();

                //Set the user interface user fo navigation visibility

                oFrame.NavigationUIVisibility = System.Windows.Navigation.NavigationUIVisibility.Visible;

                //Set the source of the current navigation, Navigate method could be used instead indeed

                oFrame.Source = new Uri(@"http://www.tunisianproducts.com/", UriKind.RelativeOrAbsolute);

                //Set the focus on the current tab

                oTabItem.Focus();

                //set the logical parent of the new frame as the focused tab item

                oTabItem.Content = oFrame;

                //This label is used to display the current uri in the status bar

                oLabel = new Label();

                oLabel.Content = @"http://www.tunisianproducts.com/";

                statusBar1.Items.Add(oLabel);

            }

     

            private void NewWindow_Click(object sender, RoutedEventArgs e)

            {

                //This enables create a new window and display it

                Window1 oWindow1 = new Window1();

                oWindow1.Show();

            }

     

            private void NewTab_Click(object sender, RoutedEventArgs e)

            {

                //This enables create a new tab and configure it then display its contents

                CreateNewTabAndBrowse();

            }

     

            private void CreateNewTabAndBrowse()

            {

                if (textBox1.Text != "")

                {

                    oTabItem = new TabItem();

                    oTabItem.Header = "Tab" + i.ToString();

                    tabControl1.Items.Add(oTabItem);

                    oTabItem.MouseDown += new MouseButtonEventHandler(oTabItem_MouseDown);

                    oFrame = new Frame();

                    oFrame.NavigationUIVisibility = System.Windows.Navigation.NavigationUIVisibility.Visible;

                    oFrame.Source = new Uri(textBox1.Text, UriKind.RelativeOrAbsolute);

                    oTabItem.Focus();

                    oTabItem.Content = oFrame;

                    i++;

                    oLabel = new Label();

                    oLabel.Content = "Last visited: " + textBox1.Text;

                    statusBar1.Items.RemoveAt(0);

                    statusBar1.Items.Add(oLabel);

                }

                else

                {

                    System.Windows.MessageBox.Show("You have to define an uri", "You have to define an uri");

                }

            }

            private void oTabItem_MouseDown(object sender, MouseEventArgs e)

            {

                //This enble to discard a tab item by just right click on it

                tabControl1.Items.Remove(tabControl1.SelectedItem);

     

            }

            private void OpenFile_Click(object sender, RoutedEventArgs e)

            {

                //This enables to open a html file in the local machine

                System.Windows.Forms.OpenFileDialog Open = new System.Windows.Forms.OpenFileDialog();

                Open.Filter = "(*.html)|*.html";

                Open.ShowDialog();

                if (Open.ShowDialog() == System.Windows.Forms.DialogResult.OK)

                    oFrame.Source = new Uri(Open.FileName);

     

     

            }

     

            private void Quit_Click(object sender, RoutedEventArgs e)

            {

                //This enables to close the current window

                this.Close();

            }

            //This button is used to directly browse to the desired internet content

            private void button1_Click(object sender, RoutedEventArgs e)

            {

                NewTab_Click(sender, e);

            }

     

        }

    }
     

  5. Now, run the application and the result will be

Finally, I can say that it is a very primary browser. It is constructed thanks to the frame object, so try to play around with it. Indeed, it could be enhanced to perform other functionalities supported browsers such as internet explorer or Opera for example. That's it 

Good Dotneting!!!


Login to add your contents and source code to this article
 About the author
 
Bechir Bejaoui
The author holds a master degree in NTIC specialized  in software developement delivered by the high school of communication SUPCOM, he also holds a bachelor degree in finance delivered by  the  economic sciences and  management  university of Tunis "FSEGT". He's a freelance developer since 2006. Actually woking on the WPF, .Net framewok 3.5, silverlight and the other .Net new features, in addition, he is painter and sculptor.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010 Professional
Microsoft Visual Studio 2010 Professional will launch on April 12, but you can beat the rush and secure your copy today by pre-ordering at the affordable estimated retail price of $549 (US). Pre-order now.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
 
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
Bejaoui.zip
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 2010  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.