Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design improvements #18300

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Design improvements #18300

wants to merge 3 commits into from

Conversation

maxkatz6
Copy link
Member

What does the pull request do?

  1. Design.DataContext should support bindings.
  2. Design.PreviewWith should work with any controls, as developer would decide previewing it.
  3. Design.PreviewWith should work with IDataTemplate, but require ContentControl with Content data set.

Untested. Need to wait for the nightly builds.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0055107-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6
Copy link
Member Author

Design.PreviewWith should be a ITemplate<Control> property to make it work unfortunately.

@maxkatz6 maxkatz6 marked this pull request as draft February 24, 2025 04:50
@maxkatz6 maxkatz6 added the needs-api-review The PR adds new public APIs that should be reviewed. label Feb 24, 2025
@MrJul
Copy link
Member

MrJul commented Mar 5, 2025

Public API for review:

namespace Avalonia.Controls
{
    public static class Design
    {
+        public static void SetPreviewWith(IDataTemplate target, Control? control);
+        public static Control? GetPreviewWith(IDataTemplate target);
    }
}

@maxkatz6
Copy link
Member Author

maxkatz6 commented Mar 6, 2025

@MrJul we can discuss another API option:

+        public static void SetPreviewWith(AvaloniaObject target, ITemplate<Control>? template)
+        public static void SetPreviewWith(ResourceDictionary target, ITemplate<Control>? template)
+        public static void SetPreviewWith(IDataTemplate target, ITemplate<Control>? template);
+        public static Control? GetPreviewWith(IDataTemplate target);

And additionally:

  1. Find a way to force XAML compiler to use ITemplate overload fixing stackoverflow for user controls. OverloadResolutionPriority support when? :). But in this specific case we can just hardcode Design as a special case.
  2. GetPreviewWith should always check if any template was saved for the control and use it instead of attached property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-previewer enhancement needs-api-review The PR adds new public APIs that should be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants