c# - Flyout.showAt() 基于内容的 ArgumentException

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

我正在尝试以这种方式使用浮出控件

 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;

最佳答案

只需使用以下方法即可解决:

 <Page.Resources>
      <Flyout x:Name="myFlyout">
           <Grid>...</Grid>
      </Flyout>
  </Page.Resources>

  myFlyout.showAt(videosGrid);

但不知道为什么它不能以其他方式工作。

关于c# - Flyout.showAt() 基于内容的 ArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23606049/

相关文章:

c# - 不可变列表不添加数据

C# 委托(delegate)和线程!

c# - Razor View 的有界属性在发布后未更新

c# - ListView : Stretch grid in custom datatemplate to max width?

c# - 将图像复制并重命名到 Windows 8 应用程序上的文件夹

windows - UWP 单个 UI 线程中的多个 View

xaml - XAML 中的中心弹出窗口

c# - 加快字节解析可能吗?

windows - 从 Windows 应用商店取消发布应用程序并为当前用户强制卸载

windows - 关联 App Store 应用程序和桌面应用程序的方法