消除XAML代码重复 [英] Eliminating XAML code duplication

查看:69
本文介绍了消除XAML代码重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在Windows Mobile应用程序中具有过渡效果,并且能够使用silverlight工具箱的过渡效果实现过渡效果.但是问题是我最终在所有XAML页面中复制了确切的代码.

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.

我在页面底部提供了MainPage.xaml的摘录和重复的工具包代码.有没有一种方法可以对此进行优化(放在一个地方并使用它)?

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

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

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>

推荐答案

使用 更新:

  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>

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

  • 这篇关于消除XAML代码重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆