Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User
Windows ; App ;

ScreenShot erstellen mit MAUI C# Desktop App

22.12.2022 (👁3588)

ScreenShot erstellen mit MAUI C# Desktop App

2022

Mit Microsoft VisualStudio 2022 und MAUI (früher Xamarin) kann man sehr einfach eine ScreenShot App erstellen.

Allerding kann die Anwendung wie immer nur sich selbst und nicht den Bildschirm aufzeichnen.

Youtube

Vorschau

namespace MauiApp1;

 

public partial class MainPage : ContentPage

{

    int count = 0;

 

    public MainPage()

    {

        InitializeComponent();

    }

 

    private async void OnCounterClicked(object sender, EventArgs e)

    {

        var shot = await TakeScreenshotAsync();

        img1.Source = shot;

    }

 

 

    public async Task<ImageSource> TakeScreenshotAsync()

    {

        if (Screenshot.Default.IsCaptureSupported)

        {

            IScreenshotResult screen = await Screenshot.Default.CaptureAsync();

            Stream stream = await screen.OpenReadAsync();

            var x = ImageSource.FromStream(() => stream);

 

            return x;

        }

 

        return null;

    }

}

 

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"

             x:Class="MauiApp1.MainPage">

 

    <ScrollView>

        <VerticalStackLayout

            Spacing="25"

            Padding="30,0"

            VerticalOptions="Center">

 

            <Button

                x:Name="CounterBtn"

                Text="ScreenShot"

                SemanticProperties.Hint="Counts the number of times you click"

                Clicked="OnCounterClicked"

                HorizontalOptions="Center" />

 

            <Image x:Name="img1" Source=""></Image>

 

        </VerticalStackLayout>

    </ScrollView>

 

</ContentPage>