Flyout.showAt() ArgumentException based on Content

ⅰ亾dé卋堺 提交于 2019-12-11 03:42:17

问题


I am trying to use a Flyout this way

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

while I have the following XAML code

<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>

Now, the problem is that I get an ArgumentException in f.showAt();

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

which is not raised if I remove the line

f.Content = this.videoFlyoutContent;

回答1:


Solved simply by using:

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

and

  myFlyout.showAt(videosGrid);

but no idea of why it didn't work the other way.



来源:https://stackoverflow.com/questions/23606049/flyout-showat-argumentexception-based-on-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!