Sign in
|
Join
|
Help
in
Sajiv Thomas (blog)
IdentityMine (group)
(Entire Site)
WPF Design and Development
IdentityMine Team Blogs
Home
Blogs
Forums
Photos
Downloads
This Blog
Home
Syndication
RSS
Atom
Comments RSS
Recent Posts
Blendables EvalBinding: Trigger without a Trigger
Silverlight 1.0 Carousel
How to change the Source property of a Frame control in WPF?
Formatting data in WPF DataBinding.
WPF-Interactive3D Toblerone
Tags
3d
blendables
Data Binding
Silverlight
Styles
xbap
Archives
January 2008
(1)
November 2007
(2)
August 2007
(1)
May 2007
(1)
April 2007
(1)
March 2007
(1)
Sajiv Thomas
WPF DataBinding, 3D, Graphics, Controls, Silverlight
How to change the Source property of a Frame control in WPF?
Suppose we have a Frame control in our application and it inherits it’s ‘DataContext’ from its parent Window. If we need to change the ‘Source’ property when a certain condition is true then we could style the Frame as seen below:
<
Style
x:Key
=
"
FrameStyle
"
TargetType
=
"
{x:Type Frame}
"
>
<
Setter
Property
=
"
Source
"
Value
=
"
{Binding XPath=@Path}
"
/><
Style.Triggers
>
<
DataTrigger
Binding
=
"
{Binding XPath=@IsRedirectionRequired}
"
Value
=
"
Yes
"
><
Setter
Property
=
"
Source
"
Value
=
"
{Binding XPath=@AlternatePath}
"
/>
</
DataTrigger
></
Style.Triggers
>
</
Style
>
We are assuming that our DataSource is an XML file which contains the path to various loose XAML files and an alternate path for each. Something like this.
<
Files
>
<
File
Name
=
"
File1
"
Path
=
"
http://www.identitymine.com
"
AlternatePath
=
"
http://www.blendables.com/
"
IsRedirectionRequired
=
"
Yes
"
/><
File
Name
=
"
File2
"
Path
=
"
http://www.google.com
"
AlternatePath
=
"
http://www.msn.com
"
IsRedirectionRequired
=
"
No
"
/>
</
Files
>
Here is a
sample.
#Note: Setting the ‘Source’ or ‘Content’ property on the Frame locally (either using DataBinding or hard coded values) as seen below will result in the style having no effect.
<
Frame
Source
=
"
{Binding XPath=@Path}
"
Grid.Column
=
"
1
"
Width
=
"
Auto
"
Height
=
"
Auto
"
Style
=
"
{StaticResource FrameStyle}
"
/>
Published
Nov 07 2007, 12:59 AM
by
Sajiv
Filed under:
Styles
Comments
No Comments
© 2007 IdentityMine, Inc.