none
windows 8项目,Grid App,如何实现不同背景相互之间的过渡变换? RRS feed

  • 问题

  • 如题,win8项目,使用VS2012,Grid App模板。如何实现不同背景相互之间的过渡变换?在点击Item项进行切换时,现在的背景由另一张背景渐变覆盖掉,而不是从黑屏慢慢渐显?这种效果可以实现吗?实现的方法是什么?
    2013年12月18日 14:57

答案

  • Hi,

    报“当前上下文不存在"TASK" 这个错误明显是你没有将TASK的命名空间加进去,你将

    using System.Threading.Tasks;

    这个命名空间加入到你报错的页面。

    前面ItemDetailPage.xaml的那段代码不好意思贴错了,将这段加进去:

      <Grid
            Style="{StaticResource LayoutRootStyle}"
            DataContext="{Binding Group}"
            d:DataContext="{Binding AllGroups[0], Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}" Name="LayoutRoot" Background="Aqua">
    
                <Grid.RowDefinitions>
                    <RowDefinition Height="140"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.Resources>
                    <Storyboard x:Name="fadeInStoryBoard">
                        <DoubleAnimation
                        Storyboard.TargetName="LayoutRoot"
                        Storyboard.TargetProperty="Opacity"
                        From="0" To="1" Duration="0:0:10"/>
                    </Storyboard>
    
                </Grid.Resources>


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • 已标记为答案 (C)sharp.sq 2013年12月25日 17:56
    2013年12月23日 7:13
    版主

全部回复

  • Hi

    可以先将一个页面的背景由亮到暗,如果进入另外一个页面的话,这个页面背景又会由暗到亮这样也能模拟您说的背景变换,如果是两个页面的那种背景覆盖,我认为实现的可能性不大,除非是在同一个页面上。

    GroupedItemsPageItemDetailPage为例,点击GroupedItemsPage上面的任何一个item,会进入到ItemDetailPage页面,您可以这样做:

    首先向GroupedItemsPagexaml页面的添加这段代码:

    <Grid Style="{StaticResource LayoutRootStyle}" Name="LayoutRoot">
            <Grid.RowDefinitions>
                <RowDefinition Height="140"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.Resources>
    
                <Storyboard x:Name="fadeoutStoryBoard">
                    <DoubleAnimation
                        Storyboard.TargetName="LayoutRoot"
                        Storyboard.TargetProperty="Opacity"
                        From="1" To="0" Duration="0:0:10"/>
                </Storyboard>
            </Grid.Resources>

    接着在它的cs页面找到ItemView_ItemClick这个方法,向里面添加如下代码:

    async void ItemView_ItemClick(object sender, ItemClickEventArgs e)
            {
                // Navigate to the appropriate destination page, configuring the new page
                // by passing required information as a navigation parameter
                var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;
                fadeoutStoryBoard.Begin();
                await Task.Delay(10000);
                this.Frame.Navigate(typeof(ItemDetailPage), itemId);
            }

    然后在ItemDetailPagexaml页面添加如下代码:

    <Grid
            Style="{StaticResource LayoutRootStyle}"
            DataContext="{Binding Group}"
            d:DataContext="{Binding AllGroups[0], Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}" Name="LayoutRoot" Background="Aqua">
    
            <Grid.RowDefinitions>
                <RowDefinition Height="140"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.Resources>
    

    向它的cs页面的LoadState将下面的代码加在该方法的第一行:

    fadeInStoryBoard.Begin();





    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    2013年12月19日 8:47
    版主
  • 按照您所说我已进行了操作,可是在GroupItemsPage.xaml.cs页面出现了这个错误:当前上下文不存在"TASK"。无法调试。请问如何解决?还有,在ItemDetailPage.xaml.cs下也出现了错误:当前上下文不存在名称“fadeInStoryBoard"。

    在ItemDetailPage.xaml下,若添加Background="Aqua"会出现错误导致无法运行。请您帮助解决,谢谢~!

    2013年12月20日 9:12
  • Hi,

    报“当前上下文不存在"TASK" 这个错误明显是你没有将TASK的命名空间加进去,你将

    using System.Threading.Tasks;

    这个命名空间加入到你报错的页面。

    前面ItemDetailPage.xaml的那段代码不好意思贴错了,将这段加进去:

      <Grid
            Style="{StaticResource LayoutRootStyle}"
            DataContext="{Binding Group}"
            d:DataContext="{Binding AllGroups[0], Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}" Name="LayoutRoot" Background="Aqua">
    
                <Grid.RowDefinitions>
                    <RowDefinition Height="140"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.Resources>
                    <Storyboard x:Name="fadeInStoryBoard">
                        <DoubleAnimation
                        Storyboard.TargetName="LayoutRoot"
                        Storyboard.TargetProperty="Opacity"
                        From="0" To="1" Duration="0:0:10"/>
                    </Storyboard>
    
                </Grid.Resources>


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • 已标记为答案 (C)sharp.sq 2013年12月25日 17:56
    2013年12月23日 7:13
    版主