Windows Presentation Foundation (WPF)

Monday, December 19, 2011

Windows Presentation Foundation (WPF) provides developers with a unified programming model for building rich Windows smart client user experiences that incorporate UI, media, and documents.
Source: MSDN.Microsoft

What's good about WPF?
Programming in WPF makes it easier for me to build greater UI especially with the use of another developer tool which is Microsoft Expression Blend
There is a behind the code - .cs where you can code the functionality of your program/project and there is .xaml where you can code your UI.

What is XAML?

XAML is a declarative markup language. As applied to the .NET Framework programming model, XAML simplifies creating a UI for a .NET Framework application. You can create visible UI elements in the declarative XAML markup, and then separate the UI definition from the run-time logic by using code-behind files, joined to the markup through partial class definitions. XAML directly represents the instantiation of objects in a specific set of backing types defined in assemblies. This is unlike most other markup languages, which are typically an interpreted language without such a direct tie to a backing type system. XAML enables a workflow where separate parties can work on the UI and the logic of an application, using potentially different tools.

When represented as text, XAML files are XML files that generally have the .xaml extension. The files can be encoded by any XML encoding, but encoding as UTF-8 is typical.

Read more...

How to Navigate using Frame (Window to Page) WPF in C#

1. Open you Visual Studio 2010
2. Select File, New, Project and Select WPF Application



3. Click Ok
And your project will look like this.

4. Go to Toolbox (On the left side your) add Frame and Button

1 frame and 1 button.

5. Right click WpfApplication (your projects title) on right side of the project
    Click Add    Then choose Page




6. Choose Page(WPF)
     Name your Page.


Then Click Add

7. Add something or anything on your page.

  Then go back to your MainWindow

8. Add this code on your XAML for Navigation

<Window.CommandBindings>
        <CommandBinding Command="NavigationCommands.GoToPage" Executed="GoToPageExecuteHandler" CanExecute="GoToPageCanExecuteHandler" />
</Window.CommandBindings>



9. Double click the button and add this code just after the public MainWindow()

private void GoToPageExecuteHandler(object sender, ExecutedRoutedEventArgs e)
        {
            frame1.NavigationService.Navigate(new Uri((string)e.Parameter, UriKind.Relative));
        }
private void GoToPageCanExecuteHandler(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }



10. Right Click the button Go to page 1 and select Properties
Type GoToPage to Command
         Page1.xaml (or the name of your page where you want to navigate) to CommandParameter



And on CommandTarget click the box or the advanced properties, Apply Data Binding



Choose Element Name, frame1 (or the title of your frame)


And that's it!


Now, press F5 to run your program.


Running program.
After clicking the Go To Page 1 button.

Read more...

About Me

Jemelyn
19 years old. Filipina. 4th year college. Computer Science student. Taylor Swift fan. Technology enthusiast. Frustrated blogger. Servant of God.
View my complete profile

  © Blogger template Brownium by Ourblogtemplates.com 2009

Back to TOP