internal static void ApplyDesignerProperties(Control target, Control source) { if (source.IsSet(WidthProperty)) target.Width = source.GetValue(WidthProperty); if (source.IsSet(HeightProperty)) target.Height = source.GetValue(HeightProperty); if (source.IsSet(DataContextProperty)) target.DataContext = source.GetValue(DataContextProperty); }
internal static void ApplyDesignerProperties(Control target, Control source) { if (source.IsSet(WidthProperty)) { target.Width = source.GetValue(WidthProperty); } if (source.IsSet(HeightProperty)) { target.Height = source.GetValue(HeightProperty); } if (source.IsSet(DataContextProperty)) { target.DataContext = source.GetValue(DataContextProperty); } }
public void DataContext_Binding_Should_Produce_Correct_Results() { var viewModel = new { Foo = "bar" }; var root = new Decorator { DataContext = viewModel, }; var child = new Control(); var values = new List <object>(); child.GetObservable(Control.DataContextProperty).Subscribe(x => values.Add(x)); child.Bind(Control.DataContextProperty, new Binding("Foo")); // When binding to DataContext and the target isn't found, the binding should produce // null rather than UnsetValue in order to not propagate incorrect DataContexts from // parent controls while things are being set up. This logic is implemented in // `Avalonia.Markup.Data.Binding.Initiate`. Assert.True(child.IsSet(Control.DataContextProperty)); root.Child = child; Assert.Equal(new[] { null, "bar" }, values); }