in

WPF Design and Development

IdentityMine Team Blogs

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:

Comments

No Comments
© 2007 IdentityMine, Inc.
Powered by Community Server (Commercial Edition), by Telligent Systems