GithubHelp home page GithubHelp logo

vladislavantonyuk / mauisamples Goto Github PK

View Code? Open in Web Editor NEW
631.0 23.0 170.0 15.84 MB

.NET MAUI Samples

Home Page: https://vladislavantonyuk.azurewebsites.net/articles?categoryName=.NET%20MAUI/Xamarin

License: MIT License

C# 97.63% HTML 0.93% CSS 1.18% Swift 0.20% JavaScript 0.04% Shell 0.01% PowerShell 0.01%
maui maui-blazor sqlite azure blazor dotnet dotnet-maui dotnet-maui-blazor kanban-board paint

mauisamples's Introduction

Hi there ๐Ÿ‘‹ I'm Vladislav

I am a Senior software engineer at DataArt, Microsoft MVP, and maintainer of .NET MAUI Community Toolkit.

๐Ÿ“ซ You can reach me at https://vladislavantonyuk.github.io

YouTube Channel Subscribers

Buy Me A Coffee

My GitHub stats

Top Langs

mauisamples's People

Contributors

deepsource-autofix[bot] avatar dependabot[bot] avatar imgbot[bot] avatar imgbotapp avatar jfs-dev avatar vladislavantonyuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mauisamples's Issues

iOS implementation limited to height of device with scrollview

Do you know if the iOS implementation is limited to where if you have a scroll view as part of your view you are limited to the height of the device? IE. scroll view won't work in iOS? I have it working on android on emulator and device and scroll but iOS appears to be limited to the height of the screen.

How to use a existing sqlite database file?

The existing sqlite database file can not be found with MauiAsset build action.
The file is setting as follows,
image
Construct a SQLiteConnection will create a new file. The origin file can be found by FileSystem.OpenAppPackageFileAsync

internal static class Database
    {
        string databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "database.db");

        public static SQLiteConnection CreateConnection()
        {
            return new SQLiteConnection(databasePath);
        }
    }

AuthService not found

Hi,
I have downloaded the whole solution and it works on Windows but when I run on the Android 33 emulator, I get this error:

System.IO.FileNotFoundException: 'Could not load file or assembly 'AuthServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.'

iOSExtensions doesnt work with net maui

your code doesnt work for me :( both in my own project, and in your Maui examples, the following error comes up "Error MSB6006: "ditto" was terminated with code 1.". Do you have any suggestions?

MauiTabView: IndicatorView+CarouselView issues

Hi,

I'd like to have a TabView header that looks like the TabbedPage header (icon+title ; tab header fills the whole width of the page).

So, two questions about the MauiTabView IndicatorView+CarouselView example:

  • the Title binding in the IndicatorView does not work. Is there a fix for that?
  • the IndicatorView is horizontally centered. Is there a way to make it fill the whole width of the page (in XF, FillAndExpand)?

Thanks

.NET MAUI Localization iOS

Hi! I have followed your guide about localization in .NET MAUI, but I'm facing an issue on iOS devices. I attempted to implement localization in a new project, following your guide step by step, and also downloaded your sample code from Github. While the localization worked as expected on Android devices, I encountered an issue on iOS devices where the localization did not change.

I was wondering if anyone else has experienced this issue, and if there are any known solutions or workarounds. Thank you for your help!

BottomDrawer not working on Android .net-7.0

I'm running into two issues trying to get the bottomdrawer example code. First, it seems like Android.Resources.Content.Id doesn't exist, at least not in .net 7.

I've replaced it with Resource.Id.content, but I'm not sure 100% that's correct.

Second, is I am getting an exception with getTheme() at runtime when the bottom sheet is trying to open

image

  Message=Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference```

about db

i have used your SQLite project and it has been successfully run. Thanks. I have another question to ask. Can Maui connect to the Firebird database?

android - bluetooth permissions are set / but still seeing a crash

Screenshot 2023-03-12 at 12 23 51 am

I can see the bluetooth permission is there.

When I ran this similar (outdated) code - it works fine .
https://github.com/TimoKinnunen/MauiXAMLBluetoothLE/blob/6c328d37ac5df6612dc288567f97a6b668da3ce0/MauiXAMLBluetoothLE/Services/BluetoothLEService.cs

seems like you need to request permission like this (specifically for android/ other platforms - doesn't matter)

https://github.com/TimoKinnunen/MauiXAMLBluetoothLE/blob/6c328d37ac5df6612dc288567f97a6b668da3ce0/MauiXAMLBluetoothLE/Services/BluetoothLEService.cs
Screenshot 2023-03-12 at 12 26 34 am

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" package="com.vladislavantonyuk.mauibluetooth" android:versionName="1.0">
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.BLUETOOTH" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
  <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
  <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
  <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" android:name="crc64d8fabeac2e8e5729.MainApplication" android:label="MauiBluetooth" android:debuggable="true" android:extractNativeLibs="true">
    <activity android:configChanges="density|orientation|smallestScreenSize|screenLayout|screenSize|uiMode" android:theme="@style/Maui.SplashTheme" android:name="crc64d8fabeac2e8e5729.MainActivity" android:exported="true">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:configChanges="orientation|screenSize" android:exported="true" android:name="crc6468b6408a11370c2f.WebAuthenticatorIntermediateActivity" />
    <provider android:authorities="com.vladislavantonyuk.mauibluetooth.fileProvider" android:exported="false" android:grantUriPermissions="true" android:name="microsoft.maui.essentials.fileProvider">
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/microsoft_maui_essentials_fileprovider_file_paths" />
    </provider>
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Connectivity Broadcast Receiver" android:name="crc64e53d2f592022988e.ConnectivityBroadcastReceiver" />
    <activity android:configChanges="orientation|screenSize" android:exported="true" android:name="crc64ba438d8f48cf7e75.IntermediateActivity" />
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Battery Broadcast Receiver" android:name="crc640a8d9a12ddbf2cf2.BatteryBroadcastReceiver" />
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Energy Saver Broadcast Receiver" android:name="crc640a8d9a12ddbf2cf2.EnergySaverBroadcastReceiver" />
    <service android:name="crc64396a3fe5f8138e3f.KeepAliveService" />
    <provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="1999999999" android:authorities="com.vladislavantonyuk.mauibluetooth.mono.MonoRuntimeProvider.__mono_init__" />
  </application>
  <!--suppress UsesMinSdkAttributes-->
  <uses-sdk android:minSdkVersion="21" />
</manifest>

Dynamic FAB

I implemented the FAB using the pattern you suggested in your post. In the image you can see the FAB with a background of green. The collectionview behind it has a tapgesturerecognizer on each item that pulls up the bottomsheet with details of each book. The problem with the FAB is that the collectionview tap is recognized vs the button in the expander view content. Any thoughts on how to resolve that?

Thanks

image

Maui Localisation: Binding the Key of the string

i am currently trying to implement your Markup Extention for translating strings via the AppResources, as you explained it here.

I can successfully use the Markup Extention in that way: EigenschaftName="{xamlExt:Translate String10423}"

But now i got a Problem. The control where i use that code, is within a DataTemplate. That template is within a CollectionView.
You already got it, i think. I need to Bind the Key of the string to the underlying object.

How do i do this? I made a screenshot here:
(Just have a look at row 39, where i need the Binding)

grafik

Kanbas board - Errror: Layout cycle detected

Hello,

I am trying to run the example on windows and I am getting the following error:


    {Microsoft.UI.Xaml.UnhandledExceptionEventArgs}
    Exception: {"A cycle occurred while laying out the GUI."}
    Handled: false
    Message: "Layout cycle detected.  Layout could not complete."

I attach an image of the dependencies I am using. I don't know if anything extra needs to be done to be able to run the example.

Thank you!

error

MauiMaps Android removed pin still appears on map

When I attempt to remove pin on MauiMaps Android, removed pin still appears on map.
I noticed in Android CustomMapHandler Markers is never is set to anything.
I added the following lines to AddPins() after the check for null at start of methos:
if (Markers == null) Markers = new List<Marker>();
Then the pin gets removed from map as expected.

Another issue I see and dont understand is the Action finished method for ImageSource.LoadImage appears to be called 4 times for each ImageSource.LoadImage () request. I examined Markers after adding a pin and there are 4 new Marker entries for an added pin.
I am using the latest version on the repository and Microsoft Visual Studio Community 2022 (64-bit) - Preview
Version 17.6.0 Preview 2.0

Android: Is there any way to allow touching outside the BottomSheet without closing the bottomsheet! Is it possible to behave like standard sheet and not like a modal sheet

   I have tried this but no luck!!
   
    var bottomSheetDialog = new BottomSheetDialog(Platform.CurrentActivity?.Window?.DecorView.FindViewById(Android.Resource.Id.Content)?.Context ?? throw new InvalidOperationException("Context is null"));
    bottomSheetDialog.SetContentView(bottomSheetContent.ToPlatform(page.Handler?.MauiContext ?? throw new Exception("MauiContext is null")));


    // Allow touches on the underlying page
    bottomSheetDialog.Window?.ClearFlags(WindowManagerFlags.NotTouchable);
    bottomSheetDialog.Window?.ClearFlags(WindowManagerFlags.DimBehind);
    bottomSheetDialog.Window?.ClearFlags(WindowManagerFlags.NotFocusable);

    // Set the behavior of the bottom sheet
    bottomSheetDialog.Behavior.Hideable = true;
    bottomSheetDialog.Behavior.FitToContents = true;
    bottomSheetDialog.SetCancelable(true);
    bottomSheetDialog.Behavior.HalfExpandedRatio = 0.5f;

    bottomSheetDialog.Show();
    return bottomSheetDialog;
    
    on iOS is working as intended when using medium or large detents!

Bluetooth implementation in .NET MAUI

Hi thanks for the good work.

btw, Can you advise or post some sample code about Implementing Bluetooth (discover, read) in .NET MAUI Android?

highly appreciated your help on this.

Thanks

[Android]System.Threading.Tasks.TaskCanceledException: A task was canceled in MauiMaps Sample

{System.Threading.Tasks.TaskCanceledException: A task was canceled.
at Microsoft.Maui.Controls.StreamImageSource.Microsoft.Maui.IStreamImageSource.GetStreamAsync(CancellationToken userToken) in D:\a_work\1\s\src\Controls\src\Core\StreamImageSource.cs:line 48
at Microsoft.Maui.Controls.Compatibility.Platform.Android.ImageLoaderSourceHandler.LoadImageAsync(ImageSource imagesource, Context context, CancellationToken cancelationToken) in D:\a_work\1\s\src\Compatibility\Core\src\Android\Renderers\ImageLoaderSourceHandler.cs:line 19

at CustomizedMap.Platforms.Android.CustomMapHandler.AddPins(IEnumerable`1 mapPins) in {folder path here}\Platforms\Android\CustomMapHandler.cs:line 97}

The repro project is here:
https://github.com/HobDev/CustomPinSample

[BUG] Transparent color on Popup not setting correctly in iOS

Setting the Popup.Color property on iOS to Transparent doesnt make the Popup Background transparent it stays gray. Appersntly that is because iOS handles page backgrounds differently than Android in terms of transparency, it us unfortunate because it doesnt provide the same look as Android and it becomes unusable. In pursuit curreny of thinking of a workaround. Any suggestions?

Very slow if I add a lot of CustomPins

Hello Vladislav, good job, but when I add arround 1000 custom pins the adding process gets very slow and a lot of GC is happening.
I made my own logic now, but maybe there is a better solution.
The problem is ... if I add the, lets say, the tenth marker , your algorithm deletes all the 9 that already added and added it again.
This get's worse the more markers you add.

MauiMaps CustomPin iOS Location and Label Set properties ignored after pin added to the map.

CustomPin once created loses base class functionality. When I assign Location to the pin after it was added to the map, it is not reflected on the map. Neither does changing pin Label text.
If pin is created with IsDraggable set to true, it can be dragged across the map. When I check the Location property after dragging to a new position, coordinates are same as passed in the Pin constructor.
Custom pins in your example represent cities. Cities don't move. If the pin represents something moving like a vehicle it would be an issue.
I did not test for Android.

Card stack layout with flip card

Hi,
I'm looking at your code for the card stack layout and it is almost what I'm looking for ๐Ÿ˜

Basically, I'm learning MAUI and I want to create an app with flash cards. So, I arrived at the point where I display the cards.

image

Now, the problems I'm facing are:

  • in the CardView I tried to change the Content but I get an error (Java.Lang.IllegalStateException: 'The specified child already has a parent. You must call removeView() on the child's parent first.', different in Windows)
  • if I add in the CardView a TapGesture, the SwipeGesture or PanGesture are not effected the view, although they are fired.
var tapGesture = new TapGestureRecognizer();
tapGesture.Tapped += TapGesture_Tapped;
GestureRecognizers.Add(tapGesture);

Do you have any advice or code for that? Thank you in advance,
Enrico

Bottom Sheet Android

Works fine on iOS but the sample code for android looks like this, how do I remove the container behind it?

Maui - Auth

Hey,

I'm trying out your sample https://github.com/VladislavAntonyuk/MauiSamples/blob/main/Auth/MauiAuth but no matter what I try, each time I attempt to login through the web redirect on Android I get the notification: unauthorized_client: The cllient does not exist or is not enabled for consumers.

I guess I need to tweak something in Azure on the app registration, but I do not know what. I think I have the correct redirect url's enabled.

Any tips?

Drag issue in Mauipaint

When I drag the. json file into the window, the file cannot be loaded. Is it related to my computer system settings?

Support for a close box.

I wanted to put a close box on the bottomsheet view that would close the bottomsheet when tapped. It works fine on android but not iOS iOS it hides the bottomsheet but the UI becomes locked.

In my ModelView I have the following command.


        [RelayCommand]
        public async void HideBottomSheet()
        {
#if ANDROID || IOS

            Application.Current.MainPage.HideBottomSheet();
#endif
        }

In Android PageExtensions I changed the code as follows...
A class variable d; set d to the bottomSheetdialog; and the hide it when the command is called.


public static partial class PageExtensions
{
    static BottomSheetDialog d;
    public static void ShowBottomSheet(this Page page, IView bottomSheetContent, bool dimDismiss)
    {
        var bottomSheetDialog = new BottomSheetDialog(Platform.CurrentActivity?.Window?.DecorView.FindViewById(Android.Resource.Id.Content)?.Context ?? throw new InvalidOperationException("Context is null"));
        bottomSheetDialog.SetContentView(bottomSheetContent.ToPlatform(page.Handler?.MauiContext ?? throw new Exception("MauiContext is null")));
        bottomSheetDialog.Behavior.Hideable = dimDismiss;
        bottomSheetDialog.Behavior.FitToContents = true;
        bottomSheetDialog.Show();
        d = bottomSheetDialog;
       
      
    }
    public static void HideBottomSheet (this Page page)
    {
        d.Hide();
    }
}

Did the same kind of thing on iOS but I suspect I have gotten the wrong variable and something is not working...

Any suggestions on how I can update the iOS one to work without hanging?

Thanks

public static partial class PageExtensions
{
    public static void HideBottomSheet(this Page page)
    {
        c.PresentedView.Hidden = true;

    }
    static UISheetPresentationController c;
    public static void ShowBottomSheet(this Page page, IView bottomSheetContent, bool dimDismiss)
	{
		var mauiContext = page.Handler?.MauiContext ?? throw new Exception("MauiContext is null");
		var viewController = page.ToUIViewController(mauiContext);
		var viewControllerToPresent = bottomSheetContent.ToUIViewController(mauiContext);
	
		var sheet = viewControllerToPresent.SheetPresentationController;
				
		if (sheet is not null)
		{
			sheet.Detents = new[]
			{
				UISheetPresentationControllerDetent.CreateMediumDetent(),
				UISheetPresentationControllerDetent.CreateLargeDetent(),
			};
			sheet.LargestUndimmedDetentIdentifier = dimDismiss ? UISheetPresentationControllerDetentIdentifier.Unknown : UISheetPresentationControllerDetentIdentifier.Medium;
			sheet.PrefersScrollingExpandsWhenScrolledToEdge = false;
			sheet.PrefersEdgeAttachedInCompactHeight = true;
			sheet.WidthFollowsPreferredContentSizeWhenEdgeAttached = true;
		}

		viewController.PresentViewController(viewControllerToPresent, animated: true, null);
		c = sheet;
		
	}

}

Localization Sample

It is very nice and working well, but how can i localize the text from code pls ?

Custom pins are not shown anymore on iOS after maps pin itemsource changes

Dear Vladislav,

first of all: Thank you for your great examples and blog posts.
Second: I have an interesting problem with custom map pins only on iOS. When the Map view and viewmodel is loaded the first time, everything works fine, but after i change the itemsource for the pins (e.g. sort the collection - > Venues = new ObservableCollection(CachedVenues.OrderBy(x => x.Name));) the pins are gone, together with the own position marker on the map view. The fail is quiet (no exception whatsoever).

I tried to troubleshoot for 2 days now with no avail. I suspect the problem in the addAnnotation method together with the GetViewForAnnotations method within MapExtensions

Within the GetViewForAnnotations the condition

if (annotation is CustomAnnotation customAnnotation) {...}

triggers the first time round but not after the itemsource is changed, because then only MKPointAnnotation types are available.

To confirm: the code works as intended as long as the itemsource is not changed. As soon as the itemsource is sorted and the change notified all markers together with the own position marker are gone from the map.

I would be really greatful if you can give me a hint to point into the right direction if you got any idea.

Thanks and Stay Safe,

Rgds Vinc

<maps:Map x:Name="mapIOS" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" IsShowingUser="True" IsTrafficEnabled="True" ItemsSource="{Binding DataService.Venues, Mode=OneWay}"> <maps:Map.ItemTemplate> <DataTemplate> <pin:CustomPin x:DataType="models:Venue" Address="{Binding Address}" ImageSource="locationpin.png" InfoWindowClicked="Pin_InfoWindowClicked" Label="{Binding Name}" Map="{x:Reference mapIOS}" MarkerClicked="Pin_MarkerClicked"> <pin:CustomPin.Location> <MultiBinding Converter="{StaticResource LatLonToLocationConverter}"> <Binding Path="Latitude" /> <Binding Path="Longitude" /> </MultiBinding> </pin:CustomPin.Location> </pin:CustomPin> </DataTemplate> </maps:Map.ItemTemplate> </maps:Map>

[iOS] Customizing Map Pins removes the Marker Click events

Hello, after following your guide on how to customize Map pins, I noticed that my MarkerClicked events are overwritten/missing. I can't seem to figure out how re-add them. The click events work when using the default map pin.

Tested on iOS 16.1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.