-
I'd like to bind a collection of complex items on a view model to the Is there an example for that somewhere? If not - does anybody have an idea on how to do that? Thanks! For example, how would I bind the public class Blog
{
public List<Post> Posts { get; set; }
public class Post
{
public string Title { get; set; }
public string Author { get; set; }
public DateTime Published { get; set; }
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Existing Examples from Sample App + Unit TestsHere's a non-trivial example from our sample app: For your specific example, you'll need to use nested-bindings which are egregiously more complex. I highly recommend avoid using nested classes in your models to avoid nested-bindings. We have a few examples of nested-bindings in our Unit Tests; here's one for example: |
Beta Was this translation helpful? Give feedback.
-
Thank you for your prompt and detailed reply! I understand that
That helps - I'll try that. Cheers! |
Beta Was this translation helpful? Give feedback.
Existing Examples from Sample App + Unit Tests
Here's a non-trivial example from our sample app:
Maui.Markup/samples/CommunityToolkit.Maui.Markup.Sample/Pages/NewsPage.cs
Line 25 in 5ab559f
For your specific example, you'll need to use nested-bindings which are egregiously more complex. I highly recommend avoid using nested classes in your models to avoid nested-bindings.
We have a few examples of nested-bindings in our Unit Tests; here's one for example:
Maui.Markup/src/CommunityToolkit.Maui.Markup.UnitTests/TypedBindingExtensionsTests.cs
Lines 297 to 312 in 5ab559f