【发布时间】:2022-06-10 21:25:49
【问题描述】:
我创建了一个非常基本的 MauiApp,因为我想在 Windows 平台上试用 MediaPicker。
于是我复制了官方documentation的代码并尝试运行我的应用程序
但是,如果我按照文档中的建议将 <uap:Capability Name="webcam"/> 添加到 Package.appxmanifest 文件中,然后运行应用程序,则会出现以下错误:
Error DEP0700: Registration of the app failed. [0x80080204] error 0xC00CE169: App
manifest validation error: The app manifest must be valid as per schema: Line 39, Column
21, Reason: 'webcam' violates enumeration constraint of 'documentsLibrary
picturesLibrary videosLibrary musicLibrary enterpriseAuthentication
sharedUserCertificates userAccountInformation removableStorage appointments contacts
phoneCall blockedChatMessages objects3D voipCall chat'.
The attribute 'Name' with value 'webcam' failed to parse. MauiApp3
所以为了解决这个问题,我尝试将功能从 <uap:Capability Name="webcam"/> 更改为 <DeviceCapability Name="webcam"/>。
这样我可以运行应用程序而不会出错,但photo 始终为空:
public async void TakePhoto(object sender, EventArgs e)
{
if (MediaPicker.Default.IsCaptureSupported)
{
FileResult photo = await MediaPicker.Default.CapturePhotoAsync();
if (photo != null)
{
// save the file into local storage
string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
using Stream sourceStream = await photo.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(localFilePath);
await sourceStream.CopyToAsync(localFileStream);
}
else
{
// *** IT ALWAYS ENTERS IN THE ELSE CLAUSE ***
// *** BECAUSE photo IS ALWAYS NULL ***
CounterBtn.Text = $"Capture is supported but {photo} is null";
}
}
}
注意:当我点击我在MainPage.xaml文件中定义的这个按钮时,上面的函数被调用:
<Button
x:Name="ImageBtn"
Text="Take Photo"
SemanticProperties.Hint="Take Image"
Clicked="TakePhoto"
HorizontalOptions="Center" />
【问题讨论】:
-
我复制了你的问题,这似乎是一个潜在的问题,考虑在 github 上提出问题:github.com/dotnet/maui/issues。
标签: c# .net-6.0 maui .net-maui maui-windows