Browse Source

Make GridSplitter.Orientation non-nullable.

As OmniXAML can't handle it.
pull/386/head
Steven Kirk 11 years ago
parent
commit
7ab944c0a5
  1. 8
      samples/XamlTestApplicationPcl/Views/MainWindow.paml
  2. 36
      src/Perspex.Controls/GridSplitter.cs

8
samples/XamlTestApplicationPcl/Views/MainWindow.paml

@ -225,13 +225,13 @@
<TextBlock Text="GridSplitter" FontWeight="Medium" FontSize="20" Foreground="#212121" />
<Grid Height="500" Width="500" ColumnDefinitions="*,Auto,*,Auto,*" RowDefinitions="*,Auto,*">
<Border Grid.Column="0" Grid.Row="0" Background="Red" />
<GridSplitter Grid.Column="0" Grid.Row="1" />
<GridSplitter Grid.Column="0" Grid.Row="1" Orientation="Horizontal" />
<Border Grid.Column="0" Grid.Row="2" Background="Yellow" />
<GridSplitter Grid.Column="1" Grid.RowSpan="3" />
<GridSplitter Grid.Column="1" Grid.RowSpan="3" Orientation="Vertical" />
<Border Grid.Column="2" Grid.RowSpan="3" Background="Green" />
<GridSplitter Grid.Column="3" Grid.RowSpan="3" />
<GridSplitter Grid.Column="3" Grid.RowSpan="3" Orientation="Vertical"/>
<Border Grid.Column="4" Grid.Row="0" Background="Blue" />
<GridSplitter Grid.Column="4" Grid.Row="1" />
<GridSplitter Grid.Column="4" Grid.Row="1" Orientation="Horizontal" />
<Border Grid.Column="4" Grid.Row="3" Background="Pink" />
</Grid>
</StackPanel>

36
src/Perspex.Controls/GridSplitter.cs

@ -23,8 +23,8 @@ namespace Perspex.Controls
/// <summary>
/// Defines the <see cref="Orientation"/> property.
/// </summary>
public static readonly PerspexProperty<Orientation?> OrientationProperty =
PerspexProperty.Register<GridSplitter, Orientation?>(nameof(Orientation));
public static readonly PerspexProperty<Orientation> OrientationProperty =
PerspexProperty.Register<GridSplitter, Orientation>(nameof(Orientation));
protected Grid _grid;
@ -42,7 +42,7 @@ namespace Perspex.Controls
/// <remarks>
/// if null, it's inferred from column/row definition (should be auto).
/// </remarks>
public Orientation? Orientation {
public Orientation Orientation {
get
{
return GetValue(OrientationProperty);
@ -75,7 +75,7 @@ namespace Perspex.Controls
protected override void OnDragDelta(VectorEventArgs e)
{
var delta = Orientation.Value == Perspex.Controls.Orientation.Vertical ? e.Vector.X : e.Vector.Y;
var delta = Orientation == Orientation.Vertical ? e.Vector.X : e.Vector.Y;
double max;
double min;
GetDeltaConstraints(out min, out max);
@ -97,30 +97,6 @@ namespace Perspex.Controls
}
}
/// <summary>
/// If orientation is not set, method automatically calculates orientation based column/row auto size.
/// </summary>
private void AutoSetOrientation()
{
if (Orientation.HasValue)
{
return;
}
var column = GetValue(Grid.ColumnProperty);
if (column < _grid.ColumnDefinitions.Count && _grid.ColumnDefinitions[column].Width.IsAuto)
{
Orientation = Perspex.Controls.Orientation.Vertical;
return;
}
var row = GetValue(Grid.RowProperty);
if (row < _grid.RowDefinitions.Count && _grid.RowDefinitions[row].Height.IsAuto)
{
Orientation = Perspex.Controls.Orientation.Horizontal;
return;
}
throw new InvalidOperationException("GridSpliter Should have Orientation, width or height set.");
}
private double GetActualLength(DefinitionBase definition)
{
var columnDefinition = definition as ColumnDefinition;
@ -162,8 +138,8 @@ namespace Perspex.Controls
{
base.OnAttachedToVisualTree(e);
_grid = this.GetVisualParent<Grid>();
AutoSetOrientation();
if (Orientation.Value == Perspex.Controls.Orientation.Vertical)
if (Orientation == Orientation.Vertical)
{
Cursor = new Cursor(StandardCursorType.SizeWestEast);
var col = GetValue(Grid.ColumnProperty);

Loading…
Cancel
Save