Replies: 4 comments 1 reply
-
Yes. for overall overview of windows app sdk, you may want to see microsoft/WindowsAppSDK#2300 (comment) and microsoft/WindowsAppSDK#1942 (comment) |
Beta Was this translation helpful? Give feedback.
-
I am still investigating how all this stuff works, but it is clear that the answer to my question is "no". More specifically, if I rephrase my question somewhat around the expectations I developed from using the Xamarin Forms dialect of XAML, the answer is NO, you cannot just use C#, at least not without lots of extra work. While trying to use controls from .NET MAUI uses WinUI3, but for the Windows platform, its bootstrap code includes an App.xaml of the Windows App SDK flavor. https://github.com/VincentH-Net/CSharpForMarkup is a library for folks who prefer C# code instead of XAML, but for WinUI3, it requires an App.xaml. The Application class is special. The "magic" is centered around that class. The magic appears to be related to I added an implementation of Like I said, I'm still figuring all this stuff out. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure how WinUI3 or UWP have changed this, but with WPF it was/is possible and fairly straightforward to make UIs and apps from code without XAML for the most part (Charles Petzold's WPF book "Applications = Code + Markup" doesn't introduce XAML at all until halfway through; I even went through the book translating the examples from C# into F#) but there were/are some exceptions like |
Beta Was this translation helpful? Give feedback.
-
You may find this conversation relevant: #4127 @MikeHillberg might find this question interesting and want to weigh in. |
Beta Was this translation helpful? Give feedback.
-
I think of XAML as an alternative syntax for writing UIs, an "upper layer" of abstraction. It gets translated to a "lower layer", such as C#, or perhaps another language. But XAML isn't strictly required. It is just another way to create objects and set properties on those objects and so on. With (possibly lots of) extra work, it is possible to create a UI in code, by using that "lower layer" directly instead of going through XAML, because that "lower layer" has no dependencies on the layer above it. In fact, because everything is expressed in WinRT interfaces, the code to interact with the "lower layer" can be written in any language with a WinRT projection.
My question: Is what I said in the previous paragraph correct?
The background of my question is this: I've been working on a Swift projection for WinRT. It's mostly working nicely. But some controls work and some crash.
TextBlock
andGrid
andSlider
andDatePicker
all work fine, butTextBox
andRatingControl
andColorPicker
do not, and I've been trying to figure out why: ericsink/SwiftWinRT#3And then I noticed that if I write the same samples in Rust, they all fail in exactly the same way as my Swift versions, so I asked a question over in the Rust Windows App SDK repo, wondering if somebody there knew why: microsoft/windows-app-rs#50
One of the folks there suggested that the failing controls are doing so because they need an
IXamlMetadataProvider
(whereas the succeeding controls apparently do not). I need to read up on that, but for the moment, it just makes me want to verify or disprove the basic understanding at the top of this post. Everything proceeds from there.I'm really hoping that my understanding of how XAML fits architecturally is correct, and that my problem with
TextBox
crashing is Something Else.Follow-up comment (as an edit, because this is a Q&A, so there are apparently no comments?):
Looking ahead to the possibility that my understanding of XAML here is just wrong, I tried to remember where I got those crazy beliefs: The Xamarin Forms version of XAML definitely worked the way I describe. With Xamarin Forms (before MAUI), it was possible to create a complete UI in either code (C#) or XAML.
Another follow-up:
Hey, I just realized that MAUI uses WinUI3 for Windows support. And MAUI has its own dialect of XAML. Doesn't that suggest (perhaps even prove) that the Microsoft.UI.Xaml.* layer is usable from code? I mean, surely MAUI XAML isn't implemented on Windows by translating to WinUI3 XAML? That would seem kinda crazy.
Beta Was this translation helpful? Give feedback.
All reactions