2012-07-05 62 views
0

我希望在我的Windows Mobile应用程序中拥有过渡效果,并且我可以使用silverlight工具包的tansition效果来实现它。但问题是我最终复制了所有XAML页面中的确切代码。消除XAML代码复制

我已经提供了MainPage.xaml和位于页面底部的重复性工具箱代码的摘录。有没有一种方法来优化(在一个地方使用它)?

在Ruby on Rails中,我只是简单地为该代码创建了一个部分。这里有类似的东西吗?

<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> 

回答

1

使用Style设置页面效果。

UPDATE:

  1. 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> 
    
  2. 的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> 
    
  3. 的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> 
    
+0

你能提供一些代码请? – bragboy

+0

@Bragboy:我更新了我的答案。 –

1

也许你可以将重复的代码分隔成UserControl