[英]'System.ArgumentException' when trying to use SetPixel (x, y, Color)
[英]CommandBarFlyout keeps throwing a System.ArgumentException when trying to use as a ContextFlyout
当我尝试使用下面的代码时。 我的调试器抛出异常
System.ArgumentException HResult=0x80070057 Message=值不在预期范围内。 Source=Windows StackTrace:在 Windows.UI.Xaml.Controls.Primitives.FlyoutBase.ShowAt(FrameworkElement placeTarget) at ProjectName.MainPage.TextBlock_ContextRequested(UIElement sender, ContextRequestedEventArgs args) 在 C:\\Users\\<\\long path>\\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)
您需要为 TextBlock 设置FlyoutBase.AttachedFlyout
,然后调用FlyoutBase.ShowAttachedFlyout
方法来显示它。
然后,在我的测试中,如果您设置 Placement="Auto",它将像您发布的一样抛出异常。
作为解决方法,请删除 CommandBarFlyout 的Placement="Auto"
,如下所示:
<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}">
<FlyoutBase.AttachedFlyout>
<CommandBarFlyout x:Name="AddDeviceFlyout">
<AppBarButton x:Name="AddDevice" Label="Add Device" Icon="Add" Click="AddDevice_Click" />
</CommandBarFlyout>
</FlyoutBase.AttachedFlyout>
</TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
private void TextBlock_ContextRequested(UIElement sender, ContextRequestedEventArgs args)
{
FlyoutBase.ShowAttachedFlyout(sender as FrameworkElement);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.