Browse Source

Updated TimeSpanTypeConverter (renamed) to support both full syntax as well as shorthand seconds only. Made CrossFade/PageSlide use simple Duration property, and removed PerspexObject base. Fixed some white space issues.

pull/197/head
Jason Jarvis 11 years ago
parent
commit
d561910554
  1. 2
      samples/XamlTestApplication/Views/MainWindow.paml
  2. 2
      src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs
  3. 15
      src/Markup/Perspex.Markup.Xaml/Converters/TimeSpanTypeConverter.cs
  4. 18
      src/Perspex.SceneGraph/Animation/CrossFade.cs
  5. 18
      src/Perspex.SceneGraph/Animation/PageSlide.cs

2
samples/XamlTestApplication/Views/MainWindow.paml

@ -6,7 +6,7 @@
<Grid RowDefinitions="Auto,*,Auto" ColumnDefinitions="*,*">
<TabControl Grid.Row="1" Grid.ColumnSpan="2" Padding="5">
<TabControl.Transition>
<PageSlide Duration="0.25" />
<PageSlide Duration="0.25" />
</TabControl.Transition>
<TabItem Header="Buttons">
<StackPanel HorizontalAlignment="Center" Width="200" VerticalAlignment="Center">

2
src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs

@ -87,7 +87,7 @@ namespace Perspex.Markup.Xaml.Context
new TypeConverterRegistration(typeof(RowDefinitions), new RowDefinitionsTypeConverter()),
new TypeConverterRegistration(typeof(Thickness), new ThicknessTypeConverter()),
new TypeConverterRegistration(typeof(Selector), new SelectorTypeConverter()),
new TypeConverterRegistration(typeof(TimeSpan), new TimeSpanConverter()),
new TypeConverterRegistration(typeof(TimeSpan), new TimeSpanTypeConverter()),
};
typeConverterProvider.AddAll(converters);

15
src/Markup/Perspex.Markup.Xaml/Converters/TimeSpanTypeConverter.cs

@ -8,7 +8,7 @@ using Perspex.Media;
namespace Perspex.Markup.Xaml.Converters
{
public class TimeSpanConverter : ITypeConverter
public class TimeSpanTypeConverter : ITypeConverter
{
public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)
{
@ -22,10 +22,15 @@ namespace Perspex.Markup.Xaml.Converters
public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
{
// TimeSpan does not parse seconds format directly, restrict
// syntax to seconds for now (ie. "0.25")
var secs = double.Parse((string)value);
return TimeSpan.FromSeconds(secs);
var valueStr = (string)value;
if (!valueStr.Contains(":"))
{
// shorthand seconds format (ie. "0.25")
var secs = double.Parse(valueStr);
return TimeSpan.FromSeconds(secs);
}
return TimeSpan.Parse(valueStr);
}
public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType)

18
src/Perspex.SceneGraph/Animation/CrossFade.cs

@ -8,21 +8,11 @@ using System.Threading.Tasks;
namespace Perspex.Animation
{
// TODO: Perhaps we want a common base for Transitions with Duration so that we can
// consolidate the property declarations, etc
//
/// <summary>
/// Defines a cross-fade animation between two <see cref="IVisual"/>s.
/// </summary>
public class CrossFade : PerspexObject, IPageTransition
public class CrossFade : IPageTransition
{
/// <summary>
/// Defines the <see cref="Duration"/> property.
/// </summary>
public static readonly PerspexProperty<TimeSpan> DurationProperty =
PerspexProperty.Register<CrossFade, TimeSpan>(nameof(Duration));
/// <summary>
/// Initializes a new instance of the <see cref="CrossFade"/> class.
/// </summary>
@ -42,11 +32,7 @@ namespace Perspex.Animation
/// <summary>
/// Gets the duration of the animation.
/// </summary>
public TimeSpan Duration
{
get { return GetValue(DurationProperty); }
set { SetValue(DurationProperty, value); }
}
public TimeSpan Duration { get; set; }
/// <summary>
/// Starts the animation.

18
src/Perspex.SceneGraph/Animation/PageSlide.cs

@ -9,21 +9,11 @@ using Perspex.Media;
namespace Perspex.Animation
{
// TODO: Perhaps we want a common base for Transitions with Duration so that we can
// consolidate the property declarations, etc
//
/// <summary>
/// Transitions between two pages by sliding them horizontally.
/// </summary>
public class PageSlide : PerspexObject, IPageTransition
public class PageSlide : IPageTransition
{
/// <summary>
/// Defines the <see cref="Duration"/> property.
/// </summary>
public static readonly PerspexProperty<TimeSpan> DurationProperty =
PerspexProperty.Register<PageSlide, TimeSpan>(nameof(Duration));
/// <summary>
/// Initializes a new instance of the <see cref="PageSlide"/> class.
/// </summary>
@ -43,11 +33,7 @@ namespace Perspex.Animation
/// <summary>
/// Gets the duration of the animation.
/// </summary>
public TimeSpan Duration
{
get { return GetValue(DurationProperty); }
set { SetValue(DurationProperty, value); }
}
public TimeSpan Duration { get; set; }
/// <summary>
/// Starts the animation.

Loading…
Cancel
Save