0

我想在我的 Windows 移动应用程序中添加过渡效果,我可以使用 silverlight 工具包的过渡效果来实现它。但问题是我最终在所有 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>
4

2 回答 2

1

也许您可以将重复代码分成UserControl?

于 2012-07-05T08:48:51.290 回答
1

使用Style设置页面效果。

更新:

  1. 样式.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. 应用程序.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>
    
于 2012-07-05T08:52:08.420 回答