Browse Source

Merge pull request #197 from jazzay/master

Animations (PageSlide and CrossFade) can now be added in Xaml files
pull/213/head
Steven Kirk 11 years ago
parent
commit
81c6d3ce0d
  1. 7
      samples/XamlTestApplication/Views/MainWindow.paml
  2. 2
      src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs
  3. 41
      src/Markup/Perspex.Markup.Xaml/Converters/TimeSpanTypeConverter.cs
  4. 1
      src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj
  5. 9
      src/Perspex.SceneGraph/Animation/CrossFade.cs
  6. 9
      src/Perspex.SceneGraph/Animation/PageSlide.cs

7
samples/XamlTestApplication/Views/MainWindow.paml

@ -3,8 +3,11 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Perspex Test Application" Height="350" Width="525" SizeToContent="WidthAndHeight" >
<Grid RowDefinitions="Auto,*">
<TabControl Grid.Row="1">
<Grid RowDefinitions="Auto,*,Auto" ColumnDefinitions="*,*">
<TabControl Grid.Row="1" Grid.ColumnSpan="2" Padding="5">
<TabControl.Transition>
<PageSlide Duration="0.25" />
</TabControl.Transition>
<TabItem Header="Buttons">
<StackPanel HorizontalAlignment="Center" Width="200" VerticalAlignment="Center">
<StackPanel.Styles>

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

@ -1,6 +1,7 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
@ -86,6 +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 TimeSpanTypeConverter()),
};
typeConverterProvider.AddAll(converters);

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

@ -0,0 +1,41 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Globalization;
using OmniXaml.TypeConversion;
using Perspex.Media;
namespace Perspex.Markup.Xaml.Converters
{
public class TimeSpanTypeConverter : ITypeConverter
{
public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(IXamlTypeConverterContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
{
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)
{
throw new NotImplementedException();
}
}
}

1
src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj

@ -48,6 +48,7 @@
<Compile Include="Converters\PerspexPropertyTypeConverter.cs" />
<Compile Include="Converters\SelectorTypeConverter.cs" />
<Compile Include="Context\PerspexWiringContext.cs" />
<Compile Include="Converters\TimeSpanTypeConverter.cs" />
<Compile Include="MarkupExtensions\BindingExtension.cs" />
<Compile Include="Converters\BrushTypeConverter.cs" />
<Compile Include="Converters\BitmapTypeConverter.cs" />

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

@ -13,6 +13,13 @@ namespace Perspex.Animation
/// </summary>
public class CrossFade : IPageTransition
{
/// <summary>
/// Initializes a new instance of the <see cref="CrossFade"/> class.
/// </summary>
public CrossFade()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="CrossFade"/> class.
/// </summary>
@ -25,7 +32,7 @@ namespace Perspex.Animation
/// <summary>
/// Gets the duration of the animation.
/// </summary>
public TimeSpan Duration { get; }
public TimeSpan Duration { get; set; }
/// <summary>
/// Starts the animation.

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

@ -14,6 +14,13 @@ namespace Perspex.Animation
/// </summary>
public class PageSlide : IPageTransition
{
/// <summary>
/// Initializes a new instance of the <see cref="PageSlide"/> class.
/// </summary>
public PageSlide()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="PageSlide"/> class.
/// </summary>
@ -26,7 +33,7 @@ namespace Perspex.Animation
/// <summary>
/// Gets the duration of the animation.
/// </summary>
public TimeSpan Duration { get; }
public TimeSpan Duration { get; set; }
/// <summary>
/// Starts the animation.

Loading…
Cancel
Save