-
-
Notifications
You must be signed in to change notification settings - Fork 109
Description
I'm wondering if I'm using wrongly the library since I'm getting this error:
1>...\ai-chef-maui\MainPage.xaml(25,28): XamlC warning XC0022: Binding could be compiled to improve runtime performance if x:DataType is specified. See https://learn.microsoft.com/dotnet/maui/fundamentals/data-binding/compiled-bindings for more information.
1>ai-chef-maui -> ...\ai-chef-maui\bin\Debug\net9.0-windows10.0.19041.0\win10-x64\ai-chef-maui.dll
1>WINAPPSDKGENERATEPROJECTPRIFILE : error : PRI175: 0x80073b0f - Processing Resources failed with error: Duplicate Entry.
1>WINAPPSDKGENERATEPROJECTPRIFILE : error : PRI277: 0x80073b0f - Conflicting values for resource 'Files/Microsoft.Maui.Controls/Compatibility/Handlers/TableView/Windows/TableViewStyles.xbf'
This is a new app, I haven't added any extra NuGets or anything.
This is all code I have:
MainPage.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:cv="clr-namespace:Camera.MAUI;assembly=Camera.MAUI"
x:Class="ai_chef_maui.MainPage">
<VerticalStackLayout Padding="20">
<!-- Camera View -->
<cv:CameraView x:Name="cameraView"
WidthRequest="300"
HeightRequest="200"
AutoStartPreview="True"/>
<!-- Buttons -->
<HorizontalStackLayout Spacing="20">
<Button Text="Capture" Clicked="OnCaptureClicked"/>
<Button Text="Analyze" Clicked="OnAnalyzeClicked"/>
</HorizontalStackLayout>
<!-- Image Gallery -->
<CollectionView x:Name="galleryView" ItemsLayout="HorizontalList">
<CollectionView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" HeightRequest="100" WidthRequest="100"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ContentPage>MainPage.xaml.cs
using Camera.MAUI;
using System.Collections.ObjectModel;
namespace ai_chef_maui
{
public partial class MainPage : ContentPage
{
private ObservableCollection<string> _images = new();
public MainPage()
{
InitializeComponent();
cameraView.CamerasLoaded += CameraView_CamerasLoaded;
}
// Load Cameras
private async void CameraView_CamerasLoaded(object sender, EventArgs e)
{
if (cameraView.NumCamerasDetected > 0)
{
cameraView.Camera = cameraView.Cameras.First(); // Use the first available camera
await cameraView.StartCameraAsync(); // Start preview
}
}
// Capture Button Click
private async void OnCaptureClicked(object sender, EventArgs e)
{
try
{
// Take a snapshot
var photoStream = await cameraView.TakePhotoAsync();
if (photoStream != null)
{
// Save the snapshot to Downloads folder
string folderPath = Path.Combine(FileSystem.AppDataDirectory, "Downloads");
Directory.CreateDirectory(folderPath); // Ensure directory exists
string fileName = $"IMG_{DateTime.Now:yyyyMMdd_HHmmss}.jpg";
string filePath = Path.Combine(folderPath, fileName);
using var newStream = File.OpenWrite(filePath);
await photoStream.CopyToAsync(newStream);
// Update gallery
_images.Add(filePath);
}
}
catch (Exception ex)
{
await DisplayAlert("Error", ex.Message, "OK");
}
}
// Analyze Button Click (Placeholder)
private async void OnAnalyzeClicked(object sender, EventArgs e)
{
await DisplayAlert("Analyze", "Feature not implemented yet!", "OK");
}
}
}MauiProgram.cs
using Camera.MAUI;
using Microsoft.Extensions.Logging;
namespace ai_chef_maui
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCameraView()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
}
}Thanks.
Note:
I have deleted the bin and obj folders multiple times without any result.
