WPF Reflections

October 22, 2008  9:58 AM

WPF – Loaded event in browser applications

Mark Shurmer Profile: MarkWPF

This is a slightly strange one to my thinking.

If you have a loaded event in a panel on a page, it will get fired multiple times.
This goes against the behaviour of a WPF application (or Winforms for that matter).
I don’t know if the same is true for an Asp.Net forms application, since I haven’t done many.

It seems to be using the Loaded event as more of an Activated event.

To see this behaviour easily:

  1. Create a WPF browser application (xbap)
  2. Add a tab control
  3. Add a panel to 1 tab
  4. Add another panel to another tab
  5. do something in Loaded event in first tab , eg change colour of the panel

When you click on second tab and back to first tab, the loaded event will be fired again


October 16, 2008  12:44 PM

WPF Resources

Mark Shurmer Profile: MarkWPF

Firstly, what is a resource?

In the world of WPF, it means two things:

  1. an assembly resource
  2. an object resource

An assembly resource is a blob of data that has been embedded in your assembly. Examples are images, videos or sounds.

An object resource is slightly different. It specifies a re-usable chunk of information, but is a .Net framework object instead.
In the WPF world, that means defining things like styles.
It also means being able to re-use those chunks in different areas of your program.

October 13, 2008  1:59 PM

WPF and Silverlight

Mark Shurmer Profile: MarkWPF

It would seem that Silverlight 2 (WPF on the web!) is getting closer and closer.

It’s very exciting of course, simply because having WPF on the web makes it more available to more people.

Microsoft have released an RC (Release Candidate) for the development world, allegedly to allow everyone to get their sites working against the final release API.
Personally, i think it’s to get the development world licking their lips at the features being included.
That works for me without a doubt 🙂

September 30, 2008  11:18 AM

WPF – adding hyperlinks to pages

Mark Shurmer Profile: MarkWPF

When you are using pages as your building blocks for WPF development, hyperlinks are a useful way to move onto different pages.
That has been proved of course on the internet for many years 🙂

As to why you might use pages, see a previous blog.

A hyperlink in the xaml world is similar to the anchor tag in html, in the respect that it goes inside relevant other tags.
For example, to add a hyperlink to a textblock, specify the hyperlink inside the textblock:

<TextBlock>My test is going to be <Hyperlink NavigateUri=”chelsea.xaml”>chels</Hyperlink> and their lack of Deco

That specifies the hyperlink, and when you click on it the NavigationService will move to the chelsea.xaml page

September 29, 2008  4:22 PM

Xbap – how to show them

Mark Shurmer Profile: MarkWPF

With a standard WPF application, you don’t really have many options as to how you display the application – it has a top level window and that’s it.

With a WPF application, you have four options on how to display your top level page in a container:

  1. Using a NavigationWindow – which gives you functionality akin to a normal WPF Window
  2. U1sing a Frame directly inside the browser, also called an Xbap or browser application
  3. Using a Frame inside another window
  4. Using a Frame inside another page

These all have slightly different advantages, and I have done a description for each:

  1. Hosting in NavigationWindow.
  2. Hosting a frame directly inside the browser
  3. Hosting a frame inside a window
  4. Hosting a frame nested inside another frame

September 29, 2008  4:21 PM

WPF – hosting pages directly in the browser

Mark Shurmer Profile: MarkWPF

For a description of what a page is see blog post.

Why would you want to place a page within the browser?
It means you can run the WPF application over the internet or an intranet without any installation at all.
Thus far,I’ve mainly seen browser applications used as demos.

You create one using the visual studio new wpf browser application template.

What is useful though, is that you can write all your views (or dialogs) as pages by using the <page> xml construct.
Then you can put them into a class library (dll to us old-uns).
That enables you to have one project that is a WPF application, and one browser application both references the common class library.
Both types of application can reference the pages, and bingo you maintain your ui logic in one place.

September 27, 2008  5:15 PM

WPF pages hosting in pages

Mark Shurmer Profile: MarkWPF

What do I mean by that?

Simply put, you can embed a page within another page.
Why would you want to do that?
It allows re-use for a start, as well as splitting functionality down into logical chunks.

In the following example, I have done just that:

First the top level window

<Window x:Class=”BlogSept.Window1″
Title=”Window1″ Height=”300″ Width=”300″>
<Frame Source=”page1.xaml” NavigationUIVisibility=”Visible”>

Then page1

<Page x:Class=”BlogSept.Page1″
<Rectangle Margin=”46,68,54,132″ Name=”rectangle1″ Stroke=”Black” Fill=”Chocolate” OpacityMask=”Beige” Opacity=”0.6″ />
<TextBox Text=”Random text” Margin=”80, 190, 10, 10″ />
<Frame Source=”page2.xaml” />

Notice how it embeds a copy of page2 inside it’s visual tree.
Here is page 2:

<Page x:Class=”BlogSept.Page2″
<Ellipse Margin=”42,71,64,118″ Name=”ellipse1″ Stroke=”Black” Fill=”BlueViolet” />

September 26, 2008  1:56 PM

Xbap – hosting pages using frames

Mark Shurmer Profile: MarkWPF

For an explanation of what an Xbap is, look at a previous blog of mine.

With Xbap pages, you have a useful resource.

You can host pages within other windows or with a special xaml construct – a frame.
To do this simply declare the frame within a window:

if page1.xaml contains a page of further xaml, it’s contents will be displayed in the window 🙂

September 24, 2008  1:22 PM

Xbap – hosting in NavigationWindow

Mark Shurmer Profile: MarkWPF

To hosting your page in a NavigationWindow, what do you need to do?

Well, not a lot actually.

You write your page, set your app.xaml’s startup uri to point to your page and run it!
It will appear in a browser if you created a browser application, or inside a NavigationWindow if it is a WPF application.

The WPF application will create a NavigationWindow instead of a Window to act as the top level container.
It also uses the page’s WindowTitle property for the caption in the NavigationWindow 🙂

The NavigationWindow class derives from Window and adds the navigation buttons and the navigation service for you.

September 23, 2008  3:55 PM

Xbap – pages instead of windows

Mark Shurmer Profile: MarkWPF

For an explanation of what an Xbap is, look at a previous blog of mine.

I have spent the last few weeks writing a Xbap (or page navigation) application in WPF.

The first thing you have to get used to is that you need to forget Windows, everything is in terms of pages.
What is a page?
Actually it looks stunningly similar to a WPF Window.
You get to use exactly the same xaml markup constructs, dockpanels, textboxes etc etc.

The advantage of Xbaps over normal WPF application is that they run in the browser (firefox as well as internet explorer) and yet you still get all of the great WPF goodies, including animations and styles.
The only restrixtion is that they need to run under partial trust rather than full trust.

What does that mean in practice?
It means that whatever zone you pick for your xbap application confines its functionality.
For example, an internet zone xbap cannot access the local file system or the registry – which is only logical

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: