VincentH-Net / CSharpForMarkup

Concise, declarative C# UI markup for .NET browser / native UI frameworks
MIT License
748 stars 43 forks source link

WPF DataTemplates not working #18

Closed VincentH-Net closed 2 years ago

VincentH-Net commented 2 years ago

When I use this markup:

            ListView(() => 
                TextBlock("Item")
                .FontSize (30) .Foreground (Black)
            ) .Height (100) .Background (Yellow)
            .Bind(vm.Items)

And bind to a collection with three items, I can see three empty items of a few pixels high

When I set a breakpoint after var ui = new Windows.DataTemplate(xaml); here, the DataTemplate does not seem to have accepted the XAML - no children loaded.

I took over the XAML from the WinUI implementation.

Could you take a look @scottcg ?

VincentH-Net commented 2 years ago

Btw I am not sure if the XAML string approach is the way to go for WPF. I also saw an example using FrameworkElementFactory to set the DataTemplate 's VisualTree

VincentH-Net commented 2 years ago

I pushed a fix for the XAML load - the data template now contains the child control. However still no visible templates.

It seems the attached property in BuildChild.Id is not invoked - it is implemented in Delegators.cs, as far as I can see it follows the MS Guidance

VincentH-Net commented 2 years ago

Fixed: a propertyChangedCallback for the attached property is necessary because GetId and SetId are not called by WPF XamlReader