Browse Source

Fix ProgressBar display.

Closes #217.
pull/278/head
Steven Kirk 11 years ago
parent
commit
78ff0ff940
  1. 1
      samples/BindingTest/MainWindow.paml
  2. 12
      src/Perspex.Base/Utilities/TypeUtilities.cs
  3. 19
      src/Perspex.Controls/ProgressBar.cs

1
samples/BindingTest/MainWindow.paml

@ -28,6 +28,7 @@
<TextBlock FontSize="16" Text="Numeric Bindings"/>
<TextBox Watermark="Double" UseFloatingWatermark="True" Text="{Binding Path=DoubleValue, Mode=TwoWay}"/>
<TextBlock Text="{Binding Path=DoubleValue}"/>
<ProgressBar Maximum="10" Value="{Binding DoubleValue}"/>
</StackPanel>
</StackPanel>
</StackPanel>

12
src/Perspex.Base/Utilities/TypeUtilities.cs

@ -93,8 +93,16 @@ namespace Perspex.Utilities
if ((value.GetType() == typeof(string) && Conversions.ContainsKey(to)) ||
(to == typeof(string) && Conversions.ContainsKey(value.GetType())))
{
result = Convert.ChangeType(value, to, culture);
return true;
try
{
result = Convert.ChangeType(value, to, culture);
return true;
}
catch
{
result = null;
return false;
}
}
else
{

19
src/Perspex.Controls/ProgressBar.cs

@ -18,19 +18,32 @@ namespace Perspex.Controls
ValueProperty.Changed.AddClassHandler<ProgressBar>(x => x.ValueChanged);
}
/// <inheritdoc/>
protected override Size ArrangeOverride(Size finalSize)
{
UpdateIndicator(finalSize);
return base.ArrangeOverride(finalSize);
}
/// <inheritdoc/>
protected override void OnTemplateApplied()
{
_indicator = this.GetTemplateChild<Border>("PART_Indicator");
UpdateIndicator(Bounds.Size);
}
private void ValueChanged(PerspexPropertyChangedEventArgs e)
private void UpdateIndicator(Size bounds)
{
if (_indicator != null)
{
double percent = Maximum == Minimum ? 1.0 : ((double)e.NewValue - Minimum) / (Maximum - Minimum);
_indicator.Width = Bounds.Width * percent;
double percent = Maximum == Minimum ? 1.0 : (Value - Minimum) / (Maximum - Minimum);
_indicator.Width = bounds.Width * percent;
}
}
private void ValueChanged(PerspexPropertyChangedEventArgs e)
{
UpdateIndicator(Bounds.Size);
}
}
}

Loading…
Cancel
Save