【发布时间】:2019-03-29 13:31:44
【问题描述】:
当我尝试使用下面的代码时。我的调试器抛出异常
System.ArgumentException HResult=0x80070057 消息=值不 落在预期范围内。源 = Windows StackTrace:在 Windows.UI.Xaml.Controls.Primitives.FlyoutBase.ShowAt(FrameworkElement 放置目标)在 ProjectName.MainPage.TextBlock_ContextRequested(UIElement 发件人, C:\Users\\MainPage.xaml.cs:第 250 行
我已经尝试了所有我知道该怎么做的事情。我尝试设置附加的弹出窗口,然后尝试显示附加的弹出窗口,如下所示。我还尝试将弹出窗口与 textblock 元素内联。我什至试图只在主 ListView 元素上显示弹出窗口(认为它可能不喜欢动态列表),但我仍然遇到同样的错误。任何帮助将不胜感激。
FlyoutBase.SetAttachedFlyout((FrameworkElement)sender, AddDeviceFlyout);
FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender);
当前代码
MainPage.xaml(为简洁起见删除了很多内容):
<Page.Resources>
<ResourceDictionary>
<CommandBarFlyout Placement="Auto" x:Name="AddDeviceFlyout">
<AppBarButton x:Name="AddDevice" Label="Add Device" Icon="Add" Click="AddDevice_Click"/>
</CommandBarFlyout>
</ResourceDictionary>
</Page.Resources>
<ListView x:Name="ProcessList" SelectionMode="Single"
ItemsSource="{x:Bind MyProcesses, Mode=OneWay}"
HorizontalContentAlignment="Stretch"
SelectionChanged="ProcessList_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="auto" HorizontalAlignment="Stretch">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock
Margin="5,20" Height="50"
FontSize="20"
ContextRequested="TextBlock_ContextRequested"
Text="{Binding ProcessName, Mode=OneWay}">
</TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
MainPage.xaml.cs (C#):
private void TextBlock_ContextRequested(UIElement sender, Windows.UI.Xaml.Input.ContextRequestedEventArgs args)
{
AddDeviceFlyout.ShowAt((FrameworkElement)sender); //This is line 250
}
构建目标:
目标版本:Windows 10 版本 1809(10.0;内部版本 17763)
最低版本:Windows 10,版本 1809(10.0;内部版本 17763)
【问题讨论】: