Browse Source

add repro for binding to attached property from style.

repro/binding-attached-property-from-style
Dan Walmsley 8 years ago
parent
commit
634617b587
  1. 7
      samples/ControlCatalog/MainWindow.xaml
  2. 10
      samples/ControlCatalog/MainWindow.xaml.cs
  3. 34
      samples/ControlCatalog/MyControl.cs

7
samples/ControlCatalog/MainWindow.xaml

@ -2,5 +2,10 @@
Title="Avalonia Control Gallery"
Icon="resm:ControlCatalog.Assets.test_icon.ico?assembly=ControlCatalog"
xmlns:local="clr-namespace:ControlCatalog">
<Window.Styles>
<Style Selector="local|MainView">
<Setter Property="local:MyControl.Proportion" Value="{Binding Proportion}" />
</Style>
</Window.Styles>
<local:MainView/>
</Window>
</Window>

10
samples/ControlCatalog/MainWindow.xaml.cs

@ -13,6 +13,7 @@ namespace ControlCatalog
this.AttachDevTools();
//Renderer.DrawFps = true;
//Renderer.DrawDirtyRects = Renderer.DrawFps = true;
DataContext = this;
}
private void InitializeComponent()
@ -24,5 +25,14 @@ namespace ControlCatalog
theme.TryGetResource("Button", out _);
AvaloniaXamlLoader.Load(this);
}
private double _proportion;
public double Proportion
{
get { return _proportion; }
set { _proportion = value; }
}
}
}

34
samples/ControlCatalog/MyControl.cs

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Text;
using Avalonia;
using Avalonia.Controls;
namespace ControlCatalog
{
public class MyControl : Control
{
public static readonly AttachedProperty<double> ProportionProperty =
AvaloniaProperty.RegisterAttached<MyControl, IControl, double>("Proportion", double.NaN);
/// <summary>
/// Gets the value of the Proportion attached property on the specified control.
/// </summary>
/// <param name="control">The control.</param>
/// <returns>The Proportion attached property.</returns>
public static double GetProportion(IControl control)
{
return control.GetValue(ProportionProperty);
}
/// <summary>
/// Sets the value of the Proportion attached property on the specified control.
/// </summary>
/// <param name="control">The control.</param>
/// <param name="value">The value of the Dock property.</param>
public static void SetProportion(IControl control, double value)
{
control.SetValue(ProportionProperty, value);
}
}
}
Loading…
Cancel
Save