Browse Source

Added a new binding syntax.

Allows binding to be done in initializer lists when using the new syntax
available in the Roslyn preview.
pull/4/head
Steven Kirk 12 years ago
parent
commit
d46f10cd53
  1. 21
      Perspex/PerspexObject.cs
  2. 43
      Perspex/PerspexProperty.cs
  3. 8
      Perspex/Themes/Default/ButtonStyle.cs
  4. 6
      Perspex/Themes/Default/CheckBoxStyle.cs
  5. 13
      TestApplication/Program.cs

21
Perspex/PerspexObject.cs

@ -123,6 +123,27 @@ namespace Perspex
}
}
/// <summary>
/// Gets or sets the value of a <see cref="PerspexProperty"/>.
/// </summary>
/// <param name="property">The property.</param>
public object this[PerspexProperty property]
{
get { return this.GetValue(property); }
set { this.SetValue(property, value); }
}
/// <summary>
/// Gets or sets the binding for a <see cref="PerspexProperty"/>.
/// </summary>
/// <param name="property">The property.</param>
public object this[PerspexProperty.BindingAccessor property]
{
get { return this.GetObservable(property.Property); }
set { this.Bind(property.Property, (IObservable<object>)value, property.Priority); }
}
/// <summary>
/// Gets all <see cref="PerspexProperty"/>s registered on a type.
/// </summary>

43
Perspex/PerspexProperty.cs

@ -105,6 +105,28 @@ namespace Perspex
return result;
}
/// <summary>
/// Provides access to a property's binding via the <see cref="PerspexObject"/>
/// indexer.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>A <see cref="BindingAccessor"/> describing the binding.</returns>
public static BindingAccessor operator!(PerspexProperty property)
{
return new BindingAccessor(property, BindingPriority.LocalValue);
}
/// <summary>
/// Provides access to a property's template binding via the <see cref="PerspexObject"/>
/// indexer.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>A <see cref="BindingAccessor"/> describing the binding.</returns>
public static BindingAccessor operator ~(PerspexProperty property)
{
return new BindingAccessor(property, BindingPriority.TemplatedParent);
}
/// <summary>
/// Gets the default value for the property on the specified type.
/// </summary>
@ -167,6 +189,27 @@ namespace Perspex
{
return this.Name;
}
public class BindingAccessor
{
public BindingAccessor(PerspexProperty property, BindingPriority priority)
{
this.Property = property;
this.Priority = priority;
}
public PerspexProperty Property
{
get;
private set;
}
public BindingPriority Priority
{
get;
private set;
}
}
}
/// <summary>

8
Perspex/Themes/Default/ButtonStyle.cs

@ -65,11 +65,13 @@ namespace Perspex.Themes.Default
{
Id = "border",
Padding = new Thickness(3),
Content = new ContentPresenter(),
Content = new ContentPresenter
{
[~ContentPresenter.ContentProperty] = control[~Button.ContentProperty],
},
[~Border.BackgroundProperty] = control[~Button.BackgroundProperty],
};
border.TemplateBinding(control, Border.BackgroundProperty);
border.Content.TemplateBinding(control, ContentPresenter.ContentProperty);
return border;
}
}

6
Perspex/Themes/Default/CheckBoxStyle.cs

@ -47,6 +47,7 @@ namespace Perspex.Themes.Default
{
Border result = new Border
{
[~Border.BackgroundProperty] = control[~CheckBox.BackgroundProperty],
Content = new StackPanel
{
Orientation = Orientation.Horizontal,
@ -69,15 +70,12 @@ namespace Perspex.Themes.Default
},
new ContentPresenter
{
[~ContentPresenter.ContentProperty] = control[~CheckBox.ContentProperty],
},
},
},
};
result.TemplateBinding(control, Border.BackgroundProperty);
StackPanel stack = (StackPanel)result.Content;
ContentPresenter cp = (ContentPresenter)stack.Children[1];
cp.TemplateBinding(control, ContentPresenter.ContentProperty);
return result;
}
}

13
TestApplication/Program.cs

@ -52,19 +52,6 @@ namespace TestApplication
Gap = 6,
Children = new PerspexList<Control>
{
new Border
{
BorderBrush = Brushes.Black,
BorderThickness = 1,
Width = 10,
Height = 10,
},
new Path
{
Data = StreamGeometry.Parse("M0,0 L10,0"),
Stroke = Brushes.Black,
StrokeThickness = 1,
},
new Button
{
Content = "Button",

Loading…
Cancel
Save