代码之家  ›  专栏  ›  技术社区  ›  Vincent

无法在UWP中更改FlipView的背景?

  •  -1
  • Vincent  · 技术社区  · 6 年前

    我发现FlipView的背景无法更改…

    <Page
        x:Class="CoreSocialistValues.Views.ImageGalleryCSV2DetailPage"
        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"
        xmlns:models="using:CoreSocialistValues.Models"
        KeyDown="OnKeyDown"
        mc:Ignorable="d">
    
        <Page.Resources>
            <Storyboard x:Name="showFlipView" Completed="OnShowFlipViewCompleted">
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="flipView" BeginTime="0:0:0.5">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="shapeGrid" BeginTime="0:0:0.5">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="previewImage" BeginTime="0:0:0.6">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </Page.Resources>
    
        <Grid>
            <FlipView Background="SeaGreen"
                x:Name="flipView"
                Visibility="Visible"
                FocusVisualPrimaryThickness="1,1,1,1"
                ItemsSource="{x:Bind Source}"
                SelectedItem="{x:Bind SelectedImage, Mode=TwoWay}">
                <FlipView.ItemTemplate>
                    <DataTemplate x:DataType="models:SampleImage">
                        <Viewbox StretchDirection="DownOnly">
                            <Image
                                x:Name="detailImage"
                                Stretch="None"
                                Source="{x:Bind Source, Mode=OneWay}" />
                        </Viewbox>
                    </DataTemplate>
                </FlipView.ItemTemplate>
            </FlipView>
    
    
            <Grid x:Name="shapeGrid"/>
            <Image
                x:Name="previewImage"
                Style="{StaticResource DetailImageStyle}"
                Source="{x:Bind SelectedImage.(models:SampleImage.Source), Mode=OneWay}" />
        </Grid>
    </Page>
    

    我试图修改FlipView的模板,但什么也没发生。

    我创建了一个新项目,FlipView的背景可以更改…

    有什么办法可以改变吗?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Xie Steven    6 年前

    请参阅imagegallerycsv2detailpage,我想将背景设置为透明,以便整个窗口的背景看起来模糊。

    为您的 FlipView 失败是因为你有一个自定义样式 翻转视图 在里面 /Styles/FlipView.xaml .在这种样式中,您将 Grid 这是你的根面板 翻转视图 的控件模板。当您设置背景时,它将覆盖背景 翻转视图 . 这就是为什么你在出发的时候总是看不到后方的原因。 翻转视图 .

    你可以用 {TemplateBinding Background} 如下所示:

    <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="FlipView">
                    <Grid Background="{TemplateBinding Background}"
    ......
    

    在那之后,如果你 Background="SeaGreen" 对于 翻转视图 ,你会发现它工作得很好。

    enter image description here

    然后,你说 that the whole window background seems blured 是的。

    为了达到这个效果,你需要应用一些 Acrylic brush 在后台。

    例如,

    <FlipView 
            x:Name="flipView" Background="{StaticResource SystemControlAcrylicWindowBrush}"
    ......