Reputation: 35552
I want to have transition effects in my windows mobile application and I was able to achieve it using the silverlight toolkit's tansition effects. But the problem is I ended up duplicating the exact code in all the XAML pages.
I have provided the excerpt of the MainPage.xaml and repetitive toolkit code sitting at the bottom of the page. Is there a way to optimize this (have in one place and use it)?
In Ruby on Rails, I would have simply created a partial for that code. Is there something similar here ?
<phone:PhoneApplicationPage
xmlns:toolkit="xyz"
xmlns="xmlnamespace_value">
<!-- PAGE DESIGN START -->
...
...
...
...
<!-- PAGE DESIGN END -->
<!-- REPEATING CODE START -->
<toolkit:TransitionService.NavigationInTransition>
<toolkit:NavigationInTransition>
<toolkit:NavigationInTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardIn"/>
</toolkit:NavigationInTransition.Backward>
<toolkit:NavigationInTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardIn"/>
</toolkit:NavigationInTransition.Forward>
</toolkit:NavigationInTransition>
</toolkit:TransitionService.NavigationInTransition>
<!-- REPEATING CODE END -->
</phone:PhoneApplicationPage>
Upvotes: 0
Views: 414
Reputation: 2417
Set up effect for page using Style.
UPDATE:
Styles.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="MyPageStyle" TargetType="Page">
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect />
</Setter.Value>
</Setter>
<Setter Property="Background" Value="AliceBlue" />
</Style>
</ResourceDictionary>
App.xaml:
<Application x:Class="WpfBrowserApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Page1.xaml">
<Application.Resources>
<ResourceDictionary Source="Styles.xaml" />
</Application.Resources>
</Application>
Page1.xaml:
<Page x:Class="WpfBrowserApplication1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Page1"
d:DesignHeight="300"
d:DesignWidth="300"
Style="{StaticResource MyPageStyle}" // Take a look at this line
mc:Ignorable="d">
<Grid />
</Page>
Upvotes: 1