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

Make binding to ItemsControl.Items a compile error. #11008

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Avalonia.Controls/Flyouts/Flyout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@ public class Flyout : PopupFlyoutBase
public static readonly StyledProperty<object> ContentProperty =
AvaloniaProperty.Register<Flyout, object>(nameof(Content));

private Classes? _classes;

/// <summary>
/// Gets the Classes collection to apply to the FlyoutPresenter this Flyout is hosting
/// </summary>
public Classes FlyoutPresenterClasses => _classes ??= new Classes();

private Classes? _classes;
public Classes FlyoutPresenterClasses
{
get => _classes ??= new Classes();
set
{
if (_classes is null)
_classes = value;
else if (_classes != value)
_classes.Replace(value);
}
}

/// <summary>
/// Defines the <see cref="FlyoutPresenterTheme"/> property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public AdderSetter(IXamlMethod getter, IXamlMethod adder)
{
AllowMultiple = true,
AllowXNull = allowNull,
AllowRuntimeNull = allowNull
AllowRuntimeNull = allowNull,
AllowAttributeSyntax = false,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode nod
on.Children[c] = new XamlAstXamlPropertyValueNode(ch,
new XamlAstNamePropertyReference(ch,
new XamlAstXmlTypeReference(ch, AvaloniaNs, "Design"),
mapTo, on.Type), directive.Values);
mapTo, on.Type), directive.Values, true);
c++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode nod
new XamlAstNamePropertyReference(d,
new XamlAstClrTypeReference(ch, declaringType, false), dataTypeProperty.Name,
on.Type),
d.Values);
d.Values,
true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode nod

on.Children[c] = new XamlAstXamlPropertyValueNode(d,
new XamlAstNamePropertyReference(d, on.Type, "Name", on.Type),
d.Values);
d.Values, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode nod
objectNode.Children[index] = new XamlAstXamlPropertyValueNode(
directive,
new XamlAstNamePropertyReference(directive, objectNode.Type, "Name", objectNode.Type),
directive.Values);
directive.Values, true);
}

return node;
}
}
}
28 changes: 27 additions & 1 deletion tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,33 @@ public void Should_Parse_And_Populate_Type_Without_Public_Ctor()
Assert.Equal("World", target.Test2);
Assert.Equal("Hello", target.Test1);
}


[Fact]
public void Can_Specify_Button_Classes()
{
var xaml = "<Button xmlns='https://github.com/avaloniaui' Classes='foo bar'/>";
var target = (Button)AvaloniaRuntimeXamlLoader.Load(xaml);

Assert.Equal(new[] { "foo", "bar" }, target.Classes);
}

[Fact]
public void Can_Specify_Flyout_FlyoutPresenterClasses()
{
var xaml = "<Flyout xmlns='https://github.com/avaloniaui' FlyoutPresenterClasses='foo bar'/>";
var target = (Flyout)AvaloniaRuntimeXamlLoader.Load(xaml);

Assert.Equal(new[] { "foo", "bar" }, target.FlyoutPresenterClasses);
}

[Fact]
public void Trying_To_Bind_ItemsControl_Items_Throws()
{
var xaml = "<ItemsControl xmlns='https://github.com/avaloniaui' Items='{Binding}'/>";

Assert.ThrowsAny<XmlException>(() => AvaloniaRuntimeXamlLoader.Load(xaml));
}

private class SelectedItemsViewModel : INotifyPropertyChanged
{
public string[] Items { get; set; }
Expand Down