Flyout.showAt()基于内容的ArgumentException

时间:2014-05-12 09:59:07

标签: c# windows-store-apps winrt-xaml windows-8.1

我试图以这种方式使用Flyout

 this.DefaultViewModel["SelectedVideo"] = vi;
 Flyout f = new Flyout();
 f.Content = this.videoFlyoutContent;
 f.ShowAt(videosGrid); // HERE I GET AN EXCEPTION

虽然我有以下XAML代码

<Page.Resource>
    <!-- ................ -->
    <!-- ................ -->
    <x:Double x:Key="FlyoutWidth">500</x:Double>
    <x:Double x:Key="FlyoutHeight">440</x:Double>
    <x:Double x:Key="FlyoutTextWidth">400</x:Double>
    <ContentControl x:Name="videoFlyoutContent">
        <Grid DataContext="{Binding SelectedVideo}" Width="{StaticResource FlyoutWidth}" Height="{StaticResource FlyoutHeight}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Image Source="{Binding thumbnail.hqDefault}" /> <!-- 480x360 -->
            <TextBlock  Grid.Row="1"
                        Text="{Binding Title}" TextTrimming="WordEllipsis" FontSize="16" FontWeight="SemiBold" TextWrapping="Wrap"
                        Style="{StaticResource UNIListItemStyle_TitleTextBlock}" HorizontalAlignment="Center" Width="{StaticResource FlyoutTextWidth}"
                        Foreground="{StaticResource VideoElement_TextForeground}"/>
        </Grid>
    </ContentControl>
</Page.Resources>

现在,问题是我在f.showAt()中得到了ArgumentException;

System.ArgumentException: Value does not fall within the expected range.
at Windows.UI.Xaml.Controls.Primitives.FlyoutBase.ShowAt(FrameworkElement placementTarget)
如果我删除了

,则不会引发

f.Content = this.videoFlyoutContent;

1 个答案:

答案 0 :(得分:2)

只需使用:

即可解决
 <Page.Resources>
      <Flyout x:Name="myFlyout">
           <Grid>...</Grid>
      </Flyout>
  </Page.Resources>

  myFlyout.showAt(videosGrid);

但不知道为什么它没有相反的方式。