【问题标题】:Flyout.showAt() ArgumentException based on ContentFlyout.showAt() ArgumentException 基于 Content
【发布时间】:2014-05-12 18:45:44
【问题描述】:

我正在尝试以这种方式使用 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;

【问题讨论】:

  • 如果“videoFlyoutContent”是一个空网格,也会发生同样的情况。

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


【解决方案1】:

只需使用即可解决:

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

  myFlyout.showAt(videosGrid);

但不知道为什么它不能以另一种方式工作。

【讨论】:

  • 可能是因为 showAt() 没有在可视化树中找到内容控件(它需要一些“参考”才能在屏幕中给浮出控件一个位置)。但是,在页面内容中的某处包含 contentcontrol 似乎不起作用。
猜你喜欢
  • 1970-01-01
  • 2015-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-15
  • 2016-06-24
  • 1970-01-01
  • 2016-05-09
相关资源
最近更新 更多