Open mrlacey opened 8 months ago
A lot of this sample makes me go "uhm.....". First of all the Children property hides the baseclass children property. Second, it seems like you're making a Layout control, but you're not inheriting from Layout or perhaps "TemplatedView". Lastly the Children property is null, so there's nothing to add the items to and you don't instantiate the collection in xaml.
Having said that, here's a quick fix for just that last bit by just returning the Children of vsl
, and your sample will run:
[ContentProperty(name: "Children")]
public class MyContainer : ContentView
{
public VerticalStackLayout vsl;
public MyContainer()
{
vsl = new VerticalStackLayout();
base.Content = vsl;
}
public IList<IView> Children => vsl.Children;
}
The Layout class is a good reference implementation of how to have children: https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/Layout/Layout.cs#L34C3-L40C40
My original repro was a simplified version of what I'm actually doing. The hiding of the property in the base class doesn't happen in my "real" code, and I hadn't noticed this issue in (what I thought was) my simplified version.
I still have old code that is based on the above that does work without issue. The same code in another project (that, as far as I can tell, has no tangible differences) doesn't work. I'd still like to know how the error message can point to an explanation, or at least more details about what's happening with the generated code.
However, @dotMorten, I can use your solution to get around my current blocker. Thank you. 😄
Description
Trying to make a simple control that sets
ContentProperty
but this results in an exception at runtimeSteps to Reproduce
Create a new project
Add this class:
Link to public reproduction project repository
No response
Version with bug
7.0.101
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
7.0.101
Affected platforms
Android, Windows, I was not able test on other platforms
Affected platform versions
No response
Did you find any workaround?
Nope. :(
Relevant log output
No response