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

BindClass method's anchor should be nullable #15725

Open
stevemonaco opened this issue May 14, 2024 · 0 comments
Open

BindClass method's anchor should be nullable #15725

stevemonaco opened this issue May 14, 2024 · 0 comments
Labels

Comments

@stevemonaco
Copy link
Contributor

stevemonaco commented May 14, 2024

Describe the bug

Continuing from #15711 (reply in thread)

Current signature is:

public static class StyledElementExtensions
{
	public static IDisposable BindClass(this StyledElement target, string className, IBinding source, object anchor) =>
		ClassBindingManager.Bind(target, className, source, anchor);
}

anchor doesn't seem to be used anymore after the 11.1 bindings refactor. So I propose:

  • Changing StyledElementExtensions.BindClass to object? anchor
  • Changing ClassBindingManager.Bind's anchor parameter to object? anchor (or removing it, since it's internal)

Alternative:

  • Create new overload of StyledElementExtensions.BindClass without anchor. Mark other overload as obsolete to be removed in v12.
  • Changing ClassBindingManager.Bind's anchor parameter to object? anchor (or removing it, since it's internal)

To Reproduce

CS8625: Cannot convert null literal to non-nullable reference type

var text = new TextBlock();

var mb = new MultiBinding()
{
    Bindings = [new Binding("IsA"), new Binding("IsB")],
    Converter = BoolConverters.And
};

text.BindClass("big", mb, null);

Expected behavior

No nullable warning. No need to use null!.

Avalonia version

Current master

OS

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant