WinRT弹出窗口的奇怪行为

时间:2016-04-29 06:46:07

标签: c# xaml gridview windows-runtime windows-8.1

我在GridView的DataTemplate中有一个Popup。 DataTemplate有2个按钮可以打开这个Popup。这非常有效。但是当滚动GridView时,我看到了一些不稳定的行为。

弹出窗口 Works perfectly well!

滚动GridView时,弹出窗口停留在页面上 Strange behaviour!

GridView ItemTemplate的XAML代码

<DataTemplate x:Key="BrandItemTemplate">
                <Grid HorizontalAlignment="Left" Width="180" Height="150" Background="White">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="125"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Popup x:Name="PagesPopup" IsOpen="{Binding IsPagesPopupOpen}">
                        <Grid Width="180" Height="150" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
                            <ListView ItemsSource="{Binding PopupList}"  Padding="8" ScrollViewer.VerticalScrollBarVisibility="Hidden" SelectionMode="None">
                                <ListView.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding}" FontSize="12" FontWeight="Medium"/>
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                                <ListView.ItemContainerStyle>
                                    <Style TargetType="ListViewItem">
                                        <Setter Property="Height" Value="30"/>
                                    </Style>
                                </ListView.ItemContainerStyle>
                            </ListView>
                            <Image Source="/Assets/Icons/closeIcon.png"  Height="25" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="8">
                                <interactivity:Interaction.Behaviors>
                                    <core:EventTriggerBehavior EventName="Tapped">
                                        <core:CallMethodAction MethodName="CloseIconTapped" TargetObject="{Binding Mode=OneWay}"/>
                                    </core:EventTriggerBehavior>
                                </interactivity:Interaction.Behaviors>
                            </Image>
                        </Grid>
                    </Popup>
                    <Image Source="{Binding Image}" Stretch="Fill"  AutomationProperties.Name="{Binding Title}" VerticalAlignment="Top"/>
                    <Border Visibility="{Binding IsNew,Converter={StaticResource BooleanToVisibilityConverter}}" VerticalAlignment="Top" Height="15" Width="25" Margin="5" Background="DarkGreen" CornerRadius="5" HorizontalAlignment="Right">
                        <TextBlock Text="NEW" FontSize="7" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Bold"/>
                    </Border>
                    <Grid Grid.Row="1" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}" Height="25">
                        <TextBlock Text="{Binding Title}" FontSize="12" AutomationProperties.Name="{Binding Title}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5 0 0 0" FontWeight="Medium"/>
                        <StackPanel Margin="0 -12 05 0" HorizontalAlignment="Right" VerticalAlignment="Top" Orientation="Horizontal">
                            <Image Source="/Assets/Icons/pagesIcon.png" Height="30">
                                <interactivity:Interaction.Behaviors>
                                    <core:EventTriggerBehavior EventName="Tapped">
                                        <core:InvokeCommandAction Command="{Binding TappedCommand}" CommandParameter="PagesIcon"/>
                                    </core:EventTriggerBehavior>
                                </interactivity:Interaction.Behaviors>
                            </Image>
                            <Image Source="/Assets/Icons/refIcon.png" Height="30" Margin="10 0 0 0">
                                <interactivity:Interaction.Behaviors>
                                    <core:EventTriggerBehavior EventName="Tapped">
                                        <core:InvokeCommandAction Command="{Binding TappedCommand}" CommandParameter="ReferencesIcon"/>
                                    </core:EventTriggerBehavior>
                                </interactivity:Interaction.Behaviors>
                            </Image>
                        </StackPanel>
                    </Grid>
                </Grid>
            </DataTemplate>

1 个答案:

答案 0 :(得分:1)

这是预期的行为。 PopUp故意拥有最高的z-index来显示所有其他元素。一个简单的解决方法是将PopUp全部删除,然后将{Binding IsPagesPopupOpen}向下移动到其中的Grid,并在具有可见性的网格Visibility上使用它转换器。除非需要将其移动到底部,否则它将显示在内容之上。

更好地解释。而不是你如何拥有它,做到这一点;

<DataTemplate x:Key="BrandItemTemplate">
  <Grid HorizontalAlignment="Left" Width="180" Height="150" Background="White">
    <Grid.RowDefinitions>
      <RowDefinition Height="125"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>        

   <Image Source="{Binding Image}" Stretch="Fill"  AutomationProperties.Name="{Binding Title}" VerticalAlignment="Top"/>
   <Border Visibility="{Binding IsNew,Converter={StaticResource BooleanToVisibilityConverter}}" VerticalAlignment="Top" Height="15" Width="25" Margin="5" Background="DarkGreen" CornerRadius="5" HorizontalAlignment="Right">
    <TextBlock Text="NEW" FontSize="7" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Bold"/>
   </Border>
     <Grid Grid.Row="1" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}" Height="25">
      <TextBlock Text="{Binding Title}" FontSize="12" AutomationProperties.Name="{Binding Title}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5 0 0 0" FontWeight="Medium"/>
      <StackPanel Margin="0 -12 05 0" HorizontalAlignment="Right" VerticalAlignment="Top" Orientation="Horizontal">
        <Image Source="/Assets/Icons/pagesIcon.png" Height="30">
          <interactivity:Interaction.Behaviors>
            <core:EventTriggerBehavior EventName="Tapped">
              <core:InvokeCommandAction Command="{Binding TappedCommand}" CommandParameter="PagesIcon"/>
            </core:EventTriggerBehavior>
          </interactivity:Interaction.Behaviors>
        </Image>
        <Image Source="/Assets/Icons/refIcon.png" Height="30" Margin="10 0 0 0">
          <interactivity:Interaction.Behaviors>
            <core:EventTriggerBehavior EventName="Tapped">
              <core:InvokeCommandAction Command="{Binding TappedCommand}" CommandParameter="ReferencesIcon"/>
            </core:EventTriggerBehavior>
          </interactivity:Interaction.Behaviors>
        </Image>
      </StackPanel>
    </Grid>

    <!-- We move it down here to ensure it appears over everything and without having to set a fixed z-index, and add your visibility converter -->
    <Grid Width="180" Height="150" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}"
          Visibility="{Binding IsPagesPopupOpen, Converter={StaticResource BooleanToVisibilityConverter}}">

      <ListView ItemsSource="{Binding PopupList}"  Padding="8" ScrollViewer.VerticalScrollBarVisibility="Hidden" SelectionMode="None">
        <ListView.ItemTemplate>
          <DataTemplate>
            <TextBlock Text="{Binding}" FontSize="12" FontWeight="Medium"/>
          </DataTemplate>
        </ListView.ItemTemplate>
        <ListView.ItemContainerStyle>
          <Style TargetType="ListViewItem">
            <Setter Property="Height" Value="30"/>
          </Style>
        </ListView.ItemContainerStyle>
      </ListView>
      <Image Source="/Assets/Icons/closeIcon.png"  Height="25" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="8">
        <interactivity:Interaction.Behaviors>
          <core:EventTriggerBehavior EventName="Tapped">
            <core:CallMethodAction MethodName="CloseIconTapped" TargetObject="{Binding Mode=OneWay}"/>
          </core:EventTriggerBehavior>
        </interactivity:Interaction.Behaviors>
      </Image>

    </Grid>

  </Grid>
</DataTemplate>