Skip to content

Design improvements #18300

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

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

Design improvements #18300

wants to merge 10 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.

@MrJul
Copy link
Member

MrJul commented Jun 11, 2025

The overloads taking ITemplate<Control> from #18300 (comment) are accepted.

Add some way in the XAML compiler to prioritize them.

@MrJul MrJul added api-approved The new public APIs have been approved. and removed needs-api-review The PR adds new public APIs that should be reviewed. labels Jun 11, 2025
@avaloniaui-bot
Copy link

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

@avaloniaui-bot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved The new public APIs have been approved. area-previewer enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants