diff --git a/samples/BindingTest/MainWindow.paml b/samples/BindingTest/MainWindow.paml
index 06416437db..3a378fcd24 100644
--- a/samples/BindingTest/MainWindow.paml
+++ b/samples/BindingTest/MainWindow.paml
@@ -28,6 +28,7 @@
+
diff --git a/src/Perspex.Base/Utilities/TypeUtilities.cs b/src/Perspex.Base/Utilities/TypeUtilities.cs
index 492aecd96c..02db883e08 100644
--- a/src/Perspex.Base/Utilities/TypeUtilities.cs
+++ b/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
{
diff --git a/src/Perspex.Controls/ProgressBar.cs b/src/Perspex.Controls/ProgressBar.cs
index 4bc10dcc3a..f9a8d867d0 100644
--- a/src/Perspex.Controls/ProgressBar.cs
+++ b/src/Perspex.Controls/ProgressBar.cs
@@ -18,19 +18,32 @@ namespace Perspex.Controls
ValueProperty.Changed.AddClassHandler(x => x.ValueChanged);
}
+ ///
+ protected override Size ArrangeOverride(Size finalSize)
+ {
+ UpdateIndicator(finalSize);
+ return base.ArrangeOverride(finalSize);
+ }
+
///
protected override void OnTemplateApplied()
{
_indicator = this.GetTemplateChild("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);
+ }
}
}