C
C#•5mo ago
Mango

Maui CommunityToolkit MediaElement

I'm trying to use the MediaElement component from CommunityToolkit.Maui to add a media player. Their guide supports 3 different schemes(?) as defined here: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/views/mediaelement?tabs=windows I don't want to use a URI resource, I would prefer to use either an embed:// or filesystem:// source but I don't know how to set either of them. I've tried filesystem with no luck. Assuming my .mp4 is located at Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Assets\Music\guidgen.mp4") what would the corresponding filesystem:// or embed:// value be?
MediaElement - .NET MAUI Community Toolkit - Community Toolkits for...
This article explains how to use MediaElement to play video and audio in a .NET MAUI application.
157 Replies
leowest
leowest•5mo ago
In the same link you provided it explains how to use embed: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/views/mediaelement?tabs=android#play-media-embedded-in-the-app-package it also explains that if u dont want to do it from xaml u have to use
Mango
MangoOP•5mo ago
that doesnt work
leowest
leowest•5mo ago
MediaSource.FromFile() or MediaSource.FromResource() and where are u placing the file? are u marking the file as resource in the properties?
Mango
MangoOP•5mo ago
that doesnt give a string
@using CommunityToolkit.Maui.Views
@inherits LayoutComponentBase

@Body

@if (_source is not null)
{
<p>@(_source ?? "")</p>
<toolkit:MediaElement Source="@_source" ShouldAutoPlay="True" ShouldShowPlaybackControls="False" />
}

@code {
string? _source;

protected override void OnInitialized()
{
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Assets\Music\guidgen.mp4");

_source = MediaSource.FromFile(path).ToString();
}
}
@using CommunityToolkit.Maui.Views
@inherits LayoutComponentBase

@Body

@if (_source is not null)
{
<p>@(_source ?? "")</p>
<toolkit:MediaElement Source="@_source" ShouldAutoPlay="True" ShouldShowPlaybackControls="False" />
}

@code {
string? _source;

protected override void OnInitialized()
{
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Assets\Music\guidgen.mp4");

_source = MediaSource.FromFile(path).ToString();
}
}
leowest
leowest•5mo ago
are u doing blazor with maui?
Mango
MangoOP•5mo ago
yeh idk, nothing ive tried from their docs work err, everything ive tried from their docs, none of it works
leowest
leowest•5mo ago
well FromResource works for me just fine
leowest
leowest•5mo ago
No description
leowest
leowest•5mo ago
song.mp3 is inside Resources/Raw as described in the docs and is set as MauiAsset which would be equal to doing Source="embed://song.mp3" via xaml but unhappily I do not know how that translates over to blazor so I can't help u on that end
Mango
MangoOP•5mo ago
where did it say to put the files in Resource\Raw?
leowest
leowest•5mo ago
all I can say is it works on maui
leowest
leowest•5mo ago
No description
No description
leowest
leowest•5mo ago
that is to handle it as resource embed Raw is the root level you can further add folders if u want to organize
Mango
MangoOP•5mo ago
show me your component code
leowest
leowest•5mo ago
and then it would be say Raw/Videos/somevideo.mp4 I also suggest u to not have files with space and weird characters what component code? my XAML? I just added the xmlns and mediaelement to it with a x:Name to access it from code behind for a quick sample
Mango
MangoOP•5mo ago
<toolkit:MediaElement Source="@_source" ShouldAutoPlay="True" ShouldShowPlaybackControls="False" />
<toolkit:MediaElement Source="@_source" ShouldAutoPlay="True" ShouldShowPlaybackControls="False" />
leowest
leowest•5mo ago
im not using blazor so I doubt it will serve to any reference
<toolkit:MediaElement x:Name="Media" />
<toolkit:MediaElement x:Name="Media" />
Mango
MangoOP•5mo ago
oh, thats xaml
leowest
leowest•5mo ago
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
yeah I dont do blazor that is pure MAUI
Mango
MangoOP•5mo ago
ah i dont know how to do that whats the namespace i need to add?
leowest
leowest•5mo ago
the package name is CommunityToolkit.Maui.MediaElement but to get the MediaSource it added using CommunityToolkit.Maui.Views;
Mango
MangoOP•5mo ago
i mean the xaml namespace i found it although i have no idea what to do now so ill have to learn xaml
leowest
leowest•5mo ago
👆 u can also refer to their sample here https://github.com/CommunityToolkit/Maui/blob/main/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml#L6 @A Certain Scientific Railgun maybe u could try asking for support on $mauitoolkit
leowest
leowest•5mo ago
the devs are very active there and answer questions often so they might be able to help u with how u bridge the mediaelement between maui and blazor if u havent got it yet
Mango
MangoOP•5mo ago
nice! im gonna have to go learn MAUI first cause I have no idea how to do anything in there that isnt blazor
leowest
leowest•5mo ago
yeah I would imagine u dont use the community toolkit for this but some blazor media element and u just give blazor the resource https://learn.microsoft.com/en-us/aspnet/core/blazor/hybrid/static-files?view=aspnetcore-6.0#net-maui so in this scenario I would expect song.mp3 to be just FileSystem.OpenAppPackageFileAsync("song.mp3"); so yeah u would just use a video element or something I guess
@if (_source is not null)
{
<p>@(_source ?? "")</p>
<video controls="controls">
<source src="@_source" type="video/mp4">
</video>
}

@code {
string? _source;

protected override void OnInitialized()
{
// assuming its on "Resources/Raw/guidgen.mp4"
_source = "guidgen.mp4";
}
}
@if (_source is not null)
{
<p>@(_source ?? "")</p>
<video controls="controls">
<source src="@_source" type="video/mp4">
</video>
}

@code {
string? _source;

protected override void OnInitialized()
{
// assuming its on "Resources/Raw/guidgen.mp4"
_source = "guidgen.mp4";
}
}
or something around those lines
Mango
MangoOP•5mo ago
so make my own component and not even need communitytoolkit
leowest
leowest•5mo ago
I dont think communitytoolkit works on blazor thou let me check I mean the "controls" one yeah I dont see any reference that the community toolkit controls would work directly on blazor it does for maui, winui3, uwp etc https://github.com/CommunityToolkit/WindowsCommunityToolkit/discussions/4141
Mango
MangoOP•5mo ago
not bad
leowest
leowest•5mo ago
learning xaml is not bad imo it open doors for a lot, but since you're previously webdev it makes sense to go for blazor https://github.com/Blazored/Video anyway see if that works for u I wonder myself if it would because I honestly dont know if blazor would be able to pick that file in that way
leowest
leowest•5mo ago
but apparently that could work the documentation is not very clear tbh
No description
Mango
MangoOP•5mo ago
I didn’t know audio and video were native html elements
leowest
leowest•5mo ago
yeah they have been for a good while on html5
Mango
MangoOP•5mo ago
yeah, i just search for how to play audio file in blazor and it gave me community toolkit
leowest
leowest•5mo ago
maybe u had maui included in it
Mango
MangoOP•5mo ago
possibly this doesnt work this doesnt work how frustrating this is lol everything ive tried does not work
leowest
leowest•5mo ago
I dont expect this to work, but I expect this to at least set the source to the name in there does it do that? I expect this to work because u need access to the file and that seems logical since you're doing it from blazor and not maui so you're essetially creating a bridge between maui and blazor with the jsinterop and passing over the stream which u obtain from the filestream but I assume u might need to use the FileSystem.OpenAppPackageFileAsync instead of just FileStream just a hunch since you're on maui
Mango
MangoOP•5mo ago
No description
Mango
MangoOP•5mo ago
it adds that
leowest
leowest•5mo ago
yes but did u look at the source
Mango
MangoOP•5mo ago
how do i see that?
leowest
leowest•5mo ago
developer's tool? and then u check if this was set properly <source src="@_source" type="video/mp4">
Mango
MangoOP•5mo ago
it added the souirce
leowest
leowest•5mo ago
so it added
Mango
MangoOP•5mo ago
No description
leowest
leowest•5mo ago
<source src="guidgen.mp4" type="video/mp4">
<source src="guidgen.mp4" type="video/mp4">
Mango
MangoOP•5mo ago
i nested it under a folder called Audio
leowest
leowest•5mo ago
ok thats good sure and its inside Resources/Raw/Audio?
Mango
MangoOP•5mo ago
so its Resource\Raw\Audio\guidgenmp4
leowest
leowest•5mo ago
ok good so we know blazor cannot access those resource directly like that
Mango
MangoOP•5mo ago
it seems like its missing something
leowest
leowest•5mo ago
so u do need to go that other route apparently
Mango
MangoOP•5mo ago
what file do i place that js function in? nvm what path does this need to be? "/data/user/0/com.mypackage.whatever/files/Content/VideoContent/MyVideo.mp4" relative to Raw?
leowest
leowest•5mo ago
https://learn.microsoft.com/en-us/aspnet/core/blazor/hybrid/static-files?view=aspnetcore-6.0#net-maui I suppose u would need to use FileSystem.OpenAppPackageFileAsync there is an example there so u would need only the relative path Audio\guideen.mp4
Mango
MangoOP•5mo ago
it works its a slow on the start
leowest
leowest•5mo ago
I would hope there is an easier way to do it but I dont do blazor so I really dont know
Mango
MangoOP•5mo ago
i would hope so too thanks for all the help
leowest
leowest•5mo ago
yeah because its loading the whole stream to pass over I would have expected the resources to be available in the root folder and that u would be able to just use the path
Mango
MangoOP•5mo ago
i wonder why i cant just host the file as a static file in wwwroot
leowest
leowest•5mo ago
maybe you can I dont know, maybe instead of making the mp4 a mauiasset u make it available in the blazor project so it would be available in the wwwroot and u can u just call the path
Mango
MangoOP•5mo ago
yeah im sure theres some benefit to putting it in Resource
leowest
leowest•5mo ago
which if the file is public anyway makes sense I doubt given this is a emulation if it was for maui itself I am sure but since its maui wrapping blazor in a webview ¯\_(ツ)_/¯
Mango
MangoOP•5mo ago
HA that works
leowest
leowest•5mo ago
there could also be limitations on say the webview not letting u play local files or something
Mango
MangoOP•5mo ago
<audio id="video" controls="" autoplay="true" style="display: none;">
<source src="audio/guidgen.mp4" type="audio/mp4">
</audio>
<audio id="video" controls="" autoplay="true" style="display: none;">
<source src="audio/guidgen.mp4" type="audio/mp4">
</audio>
leowest
leowest•5mo ago
as a mauiasset?
Mango
MangoOP•5mo ago
No description
leowest
leowest•5mo ago
ah ok in the blazor root
Mango
MangoOP•5mo ago
yeah
leowest
leowest•5mo ago
and that will be faster anyway as long as the file is not sensitive or anything and u can make it available
Mango
MangoOP•5mo ago
yeah, idc if its public currently its a free rip of a yt video
leowest
leowest•5mo ago
🫡
Mango
MangoOP•5mo ago
but i would replace it with a file that i got from an official free mp4 sample site like free stock photos but audio files or ask my music friend for one
leowest
leowest•5mo ago
whatever floats your boat its working and u know both ways of doing it althou I would hope it could use the mauiassets what a shame
Mango
MangoOP•5mo ago
whats the benefit of maui assets? a centralized way to store assets? ill have to make this app and have it be my first public repo or do a Hello world console app in as many languages that will support it
leowest
leowest•5mo ago
well because its embed so technically it would not ask u for access or anything to run the video
Mango
MangoOP•5mo ago
that work around seems jank
leowest
leowest•5mo ago
because the filesystem on winui3,android and ios suck balls its not like when u write a console app and can directly call say FIle.ReadAllLines ur tied to an API where u need to request access to certain things so reason why u need to add certain rules to the config options if ur writing it for android for example
Mango
MangoOP•5mo ago
i think iOS does that in the name of security
leowest
leowest•5mo ago
that tells the user before ahead this app use this that and this do u agree
Mango
MangoOP•5mo ago
right
leowest
leowest•5mo ago
I mean so does android right when u want to share a file in app X
Mango
MangoOP•5mo ago
iOS keeps reminding me its been x months since some app has had full access to photos, do i want to keep allowing it?
leowest
leowest•5mo ago
it says I need access to this and that do u agree before u can select photos or w/e from your storage android does have something like that as well
Mango
MangoOP•5mo ago
"Mango's awesome guid generator wants access to your files to play a fire edm song, do you concur?"
leowest
leowest•5mo ago
either way if you're doing public stuff to demonstrate your knowledge for your cv then I would suggest u learn blazor by it self nad maui by it self there is only benefits to knowing xaml
Mango
MangoOP•5mo ago
ive dabbled in blazor a bit but that was during the .netcoreapp3.1 days it hasnt changed significantly since then, other than the new hosting models
leowest
leowest•5mo ago
and that its much faster then before but still slow
Mango
MangoOP•5mo ago
and that i still dont think its as mature as the JS offerings but depending on what you want, its more than enough
leowest
leowest•5mo ago
well its obviously not because u still need to write js in it perhaps u could look at Hydro
Mango
MangoOP•5mo ago
you dont NEED to
leowest
leowest•5mo ago
but then again its not backed by any big companies
Mango
MangoOP•5mo ago
you can
leowest
leowest•5mo ago
you do need to depending on what you're doing as there are limitations of what blazor can do for u
Mango
MangoOP•5mo ago
yeah
leowest
leowest•5mo ago
Hydro extends it further
Mango
MangoOP•5mo ago
i had to when i was wanting to call bootstrap jQuery methods
leowest
leowest•5mo ago
which is cool
Mango
MangoOP•5mo ago
basically anything client side localstorage cookies
leowest
leowest•5mo ago
Hydro | Hydro
Stateful components for Razor Pages
Mango
MangoOP•5mo ago
i dont often find myself needing guid literals for stuff but when i do i dont want to have to go to ssms or some website do get one i want to use a Guid generator thats blasting edm music like its 2005
Mango
MangoOP•5mo ago
this is the background im using
No description
leowest
leowest•5mo ago
:bigthonk:
Mango
MangoOP•5mo ago
what am i thinking?? if im going to have a background of our goddess, then i have to use a Hatsune Miku song PR denied question, how do i give the page a title? I thought it was this property on 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:local="clr-namespace:GuidGen"
x:Class="GuidGen.MainPage"
Title="Guid Generator"
BackgroundColor="{DynamicResource PageBackgroundColor}">

<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
<BlazorWebView.RootComponents>
<RootComponent Selector="#app" ComponentType="{x:Type local:Components.Routes}" />
</BlazorWebView.RootComponents>
</BlazorWebView>
</ContentPage>
<?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:local="clr-namespace:GuidGen"
x:Class="GuidGen.MainPage"
Title="Guid Generator"
BackgroundColor="{DynamicResource PageBackgroundColor}">

<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
<BlazorWebView.RootComponents>
<RootComponent Selector="#app" ComponentType="{x:Type local:Components.Routes}" />
</BlazorWebView.RootComponents>
</BlazorWebView>
</ContentPage>
Title=
Mango
MangoOP•5mo ago
No description
Mango
MangoOP•5mo ago
nothing is showing
leowest
leowest•5mo ago
because that is not the shell so I think u either need to disable the backbutton in the shell or mmm or just set the title in the shell or alternatively u remove the bar and handle it all from blazor in the Shell.xaml in the header u add Shell.NavBarIsVisible="True" then u should be able to see the title per ContentPage but its like a white bar at the top
Mango
MangoOP•5mo ago
I’ll have only one page I know Blazor has a PageTitle component. Tried it, doesn’t work
leowest
leowest•5mo ago
but that is for the browser page title it would set the html <title ...> inside the header u would need to the set the maui counter part either u do it in the shell and forget or do it in the content page and set the navbar I mentioned above
Mango
MangoOP•5mo ago
i dont have a Shell.xaml
leowest
leowest•5mo ago
AppShell? can u show me your solution explorer I dont know which template u used to create it
Mango
MangoOP•5mo ago
No description
leowest
leowest•5mo ago
I see so its the non-mvvm approach, so I assume your MainPage has all the stuff
Mango
MangoOP•5mo ago
i guess so?
leowest
leowest•5mo ago
does it have 2 projects? or that is all can u show me what your MainPage.xaml looks like
Mango
MangoOP•5mo ago
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:local="clr-namespace:GuidGen"
x:Class="GuidGen.MainPage"
Title="Guid Generator"
BackgroundColor="{DynamicResource PageBackgroundColor}">

<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
<BlazorWebView.RootComponents>
<RootComponent Selector="#app" ComponentType="{x:Type local:Components.Routes}" />
</BlazorWebView.RootComponents>
</BlazorWebView>
</ContentPage>
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:local="clr-namespace:GuidGen"
x:Class="GuidGen.MainPage"
Title="Guid Generator"
BackgroundColor="{DynamicResource PageBackgroundColor}">

<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
<BlazorWebView.RootComponents>
<RootComponent Selector="#app" ComponentType="{x:Type local:Components.Routes}" />
</BlazorWebView.RootComponents>
</BlazorWebView>
</ContentPage>
MainPage.xaml.cs

namespace GuidGen;

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
MainPage.xaml.cs

namespace GuidGen;

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
leowest
leowest•5mo ago
and your App.xaml
Mango
MangoOP•5mo ago
App.xaml:

<?xml version="1.0" encoding="UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:GuidGen"
x:Class="GuidGen.App">
<Application.Resources>
<ResourceDictionary>

<Color x:Key="PageBackgroundColor">#512bdf</Color>
<Color x:Key="PrimaryTextColor">White</Color>

<Style TargetType="Label">
<Setter Property="TextColor" Value="{DynamicResource PrimaryTextColor}" />
<Setter Property="FontFamily" Value="OpenSansRegular" />
</Style>

<Style TargetType="Button">
<Setter Property="TextColor" Value="{DynamicResource PrimaryTextColor}" />
<Setter Property="FontFamily" Value="OpenSansRegular" />
<Setter Property="BackgroundColor" Value="#2b0b98" />
<Setter Property="Padding" Value="14,10" />
</Style>

</ResourceDictionary>
</Application.Resources>
</Application>
App.xaml:

<?xml version="1.0" encoding="UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:GuidGen"
x:Class="GuidGen.App">
<Application.Resources>
<ResourceDictionary>

<Color x:Key="PageBackgroundColor">#512bdf</Color>
<Color x:Key="PrimaryTextColor">White</Color>

<Style TargetType="Label">
<Setter Property="TextColor" Value="{DynamicResource PrimaryTextColor}" />
<Setter Property="FontFamily" Value="OpenSansRegular" />
</Style>

<Style TargetType="Button">
<Setter Property="TextColor" Value="{DynamicResource PrimaryTextColor}" />
<Setter Property="FontFamily" Value="OpenSansRegular" />
<Setter Property="BackgroundColor" Value="#2b0b98" />
<Setter Property="Padding" Value="14,10" />
</Style>

</ResourceDictionary>
</Application.Resources>
</Application>
App.xaml.cs:

using Microsoft.Maui.Handlers;
#if WINDOWS
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Windows.Graphics;
#endif

namespace GuidGen;

public partial class App : Application
{
private const int WindowWidth = 934;
private const int WindowHeight = 647;

public App()
{
InitializeComponent();

WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
{
#if WINDOWS
var mauiWindow = handler.VirtualView;
var nativeWindow = handler.PlatformView;
nativeWindow.Activate();
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow);
WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
appWindow.Resize(new SizeInt32(WindowWidth, WindowHeight));
#endif
});

MainPage = new MainPage();
}
}
App.xaml.cs:

using Microsoft.Maui.Handlers;
#if WINDOWS
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Windows.Graphics;
#endif

namespace GuidGen;

public partial class App : Application
{
private const int WindowWidth = 934;
private const int WindowHeight = 647;

public App()
{
InitializeComponent();

WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
{
#if WINDOWS
var mauiWindow = handler.VirtualView;
var nativeWindow = handler.PlatformView;
nativeWindow.Activate();
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow);
WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
appWindow.Resize(new SizeInt32(WindowWidth, WindowHeight));
#endif
});

MainPage = new MainPage();
}
}
leowest
leowest•5mo ago
I see since u dont have a shell I honestly dont know, maybe try setting appWIndow.Title = "..."?
Mango
MangoOP•5mo ago
well, its not in the MainPage
leowest
leowest•5mo ago
that would be in the last file u posted above just wonder if it has a Title property
Mango
MangoOP•5mo ago
Stack Overflow
How to set window title for a MAUI Blazor App targeting Windows?
Ive created a small application from the MAUI Blazor app template in MAUI preview 10 and have it targeted and running on windows. I however wish to set the title of the application which I imagined...
leowest
leowest•5mo ago
u already have the appWindow in the code above it would be a matter of u doing what I just said appWIndow.Title = "..."?
leowest
leowest•5mo ago
No description
Mango
MangoOP•5mo ago
no dice
leowest
leowest•5mo ago
what about with the override method in the link above?
Mango
MangoOP•5mo ago
this did it:
App.xaml.cs:

public partial class App : Application
{
private const int WindowWidth = 934;
private const int WindowHeight = 647;

public App()
{
InitializeComponent();

WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
{
#if WINDOWS
var mauiWindow = handler.VirtualView;
var nativeWindow = handler.PlatformView;
nativeWindow.Activate();
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow);
WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
appWindow.Resize(new SizeInt32(WindowWidth, WindowHeight));
#endif
});

MainPage = new MainPage();
}

protected override Window CreateWindow(IActivationState activationState)
{
var window = base.CreateWindow(activationState);
if (window is not null) window.Title = "YOUR WINDOW TITLE";

return window!;
}
}
App.xaml.cs:

public partial class App : Application
{
private const int WindowWidth = 934;
private const int WindowHeight = 647;

public App()
{
InitializeComponent();

WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
{
#if WINDOWS
var mauiWindow = handler.VirtualView;
var nativeWindow = handler.PlatformView;
nativeWindow.Activate();
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow);
WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
appWindow.Resize(new SizeInt32(WindowWidth, WindowHeight));
#endif
});

MainPage = new MainPage();
}

protected override Window CreateWindow(IActivationState activationState)
{
var window = base.CreateWindow(activationState);
if (window is not null) window.Title = "YOUR WINDOW TITLE";

return window!;
}
}
the CreateWindow override method
leowest
leowest•5mo ago
yeah probably because it needs to be done on creationg which is why it works on lifecycle
Mango
MangoOP•5mo ago
xaml is hella strange so thats the standard for desktop UI?
leowest
leowest•5mo ago
winui3 and maui are a different beasts but no that is not if u had a shell all u had to dos is set the title but u used some old template or something
Mango
MangoOP•5mo ago
i used what it gave me for Maui Blazor Hybrid
leowest
leowest•5mo ago
I see, yeah I never tried that to know
leowest
leowest•5mo ago
normally u have a shell
No description
leowest
leowest•5mo ago
and setting it there is all u need to do with the NavBarIsVisible to true
Mango
MangoOP•5mo ago
normally on a desktop app the title never changes regardless of what "view" or "page" you are on web is different when I use Spotify, the title is always "Spotify" etc
leowest
leowest•5mo ago
$itdepends
leowest
leowest•5mo ago
I for one like appending to the title so it changes
Mango
MangoOP•5mo ago
it depends on what the PO wants i guess
leowest
leowest•5mo ago
when I use spotify the title is always Spotify - song playing
Mango
MangoOP•5mo ago
if the PO says "static title"
leowest
leowest•5mo ago
sure
Mango
MangoOP•5mo ago
actually, i dont even see a title rn
leowest
leowest•5mo ago
are u doing this just for windows?
Mango
MangoOP•5mo ago
yeah, its for me windows only i dont have linux
leowest
leowest•5mo ago
I mean maui doesnt do linux anyway Avalonia is much better option for desktop thou
Mango
MangoOP•5mo ago
ill try that next im doing this app for the lulz
leowest
leowest•5mo ago
anyway, I dont know as I dont use blazor hybrid I have no idea what kind of maui template it uses
Mango
MangoOP•5mo ago
me neither i only know the blazor aspect of it the only maui parts i had to touch were setting the default window size and setting the title bar text everything is blazor this is the only page it has:
@page "/"

<div class="h-100 position-relative">
<div class="ms-4 position-absolute center-y">
<input type="text" value="@_value" readonly aria-readonly="true" class="me-3" style="width: 400px" />
<button class="btn btn-primary" type="button" @onclick="@(() => _value = Guid.NewGuid().ToString())">Generate</button>
</div>
</div>

<audio style="display: none;" src="audio/song.m4a" autoplay loop></audio>

@code {
string _value = "";
}
@page "/"

<div class="h-100 position-relative">
<div class="ms-4 position-absolute center-y">
<input type="text" value="@_value" readonly aria-readonly="true" class="me-3" style="width: 400px" />
<button class="btn btn-primary" type="button" @onclick="@(() => _value = Guid.NewGuid().ToString())">Generate</button>
</div>
</div>

<audio style="display: none;" src="audio/song.m4a" autoplay loop></audio>

@code {
string _value = "";
}
leowest
leowest•5mo ago
but why a input box thou bind it to some text with transparency to make it look cooler
Mango
MangoOP•5mo ago
true, it actually can be just in a <p> tag or not also, wip i dont drop character until ive done the dvd commentary is hotreload supported on apps like these? it is on standalone blazor apps
leowest
leowest•5mo ago
maui does support it dunno about hybrid blazor
Mango
MangoOP•5mo ago
No description
Mango
MangoOP•5mo ago
80% opacity on the guid background its not a text input anymore
Want results from more Discord servers?
Add your server