Skip to content

Commit

Permalink
Merge pull request #1021 from shenchauhan/effects
Browse files Browse the repository at this point in the history
Adding saturation and a simpler way to add more effects
  • Loading branch information
nmetulev authored Mar 16, 2017
2 parents 3856d1b + 56cfc2f commit c715b87
Show file tree
Hide file tree
Showing 18 changed files with 714 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
<Content Include="SamplePages\Microsoft Graph Service\user.png" />
<Content Include="SamplePages\Microsoft Translator Service\TranslatorService.png" />
<Content Include="SamplePages\OneDrive Service\OneDriveLogo.png" />
<Content Include="SamplePages\Saturation\SaturationBehavior.png" />
<Content Include="SamplePages\TileControl\Animations.png" />
<Content Include="SamplePages\TileControl\TileControl.png" />
<Content Include="SamplePages\Offset\OffsetBehavior.png" />
Expand Down Expand Up @@ -315,13 +316,15 @@
<Content Include="Assets\Prettify\run_prettify.js" />
<Content Include="SamplePages\RangeSelector\RangeSelectorCode.bind" />
<Content Include="SamplePages\AdaptiveGridView\AdaptiveGridViewCode.bind" />
<Content Include="SamplePages\samples.json" />
<Content Include="SamplePages\samples.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="readme.md" />
<Content Include="SamplePages\LiveTile\LiveTileCode.bind" />
<Content Include="SamplePages\Toast\ToastCode.bind" />
<Content Include="SamplePages\RotatorTile\RotatorTileCode.bind" />
<Content Include="SamplePages\Blur\BlurBehaviorCode.bind" />
<Content Include="SamplePages\Blur\BlurBehaviorXaml.bind" />
<Content Include="SamplePages\Saturation\SaturationBehaviorCode.bind" />
<Content Include="SamplePages\Saturation\SaturationBehaviorXaml.bind" />
<Content Include="SamplePages\Offset\OffsetBehaviorXaml.bind" />
<Content Include="SamplePages\Expander\ExpanderXaml.bind" />
<Content Include="SamplePages\Fade\FadeBehaviorXaml.bind" />
Expand Down Expand Up @@ -370,6 +373,8 @@
<Content Include="SamplePages\MarkdownTextBlock\MarkdownTextBlockCode.bind" />
<Content Include="SamplePages\OneDrive Service\OneDriveCode.bind" />
<Content Include="SamplePages\Analytics\AnalyticsCode.bind" />
<Content Include="SamplePages\Blur\BlurBehaviorCode.bind" />
<Content Include="SamplePages\Blur\BlurBehaviorXaml.bind" />
<Content Include="SamplePages\ViewExtensions\ViewExtensionsCode.bind">
<SubType>Designer</SubType>
</Content>
Expand Down Expand Up @@ -458,6 +463,9 @@
<Compile Include="SamplePages\Analytics\AnalyticsPage.xaml.cs">
<DependentUpon>AnalyticsPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\Saturation\SaturationBehaviorPage.xaml.cs">
<DependentUpon>SaturationBehaviorPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\TileControl\TileControlPage.xaml.cs">
<DependentUpon>TileControlPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -681,6 +689,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="SamplePages\Saturation\SaturationBehaviorPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\TileControl\TileControlPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

if (!AnimationExtensions.IsBlurSupported)
if (!AnimationExtensions.BlurEffect.IsSupported)
{
WarningText.Visibility = Visibility.Visible;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// XAML UIElement
<Image x:Name="MyImage" Source="ms-appx:///Assets/Photos/BigFourSummerHeat.jpg">

// C# - Saturation can be applied to any UIElement. In this case it is an image called ToolkitLogo.
using Microsoft.Toolkit.Uwp.UI.Animations;

await MyImage.Saturation(value: 10, duration: 10, delay: 0).StartAsync();

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<Page
x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.SaturationBehaviorPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages.Saturation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="WarningText"
Margin="0,20"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Foreground="{ThemeResource TextSelectionHighlightColorThemeBrush}"
Text="Blur is only available on Windows 10 Anniversary Update or greater"
TextWrapping="Wrap"
Visibility="Collapsed" />

<Image x:Name="MyImage"
Source="ms-appx:///Assets/Photos/BigFourSummerHeat.jpg">
<interactivity:Interaction.Behaviors>
<behaviors:Saturation x:Name="SaturationBehavior"
AutomaticallyStart="{Binding AutomaticallyStart.Value, Mode=OneWay}"
Delay="{Binding Delay.Value, Mode=OneWay}"
Value="{Binding Value.Value, Mode=OneWay}"
Duration="{Binding Duration.Value, Mode=OneWay}" />
</interactivity:Interaction.Behaviors>
</Image>
<StackPanel HorizontalAlignment="Right"
VerticalAlignment="Bottom">
<Button Margin="10"
Content="Apply">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:CallMethodAction MethodName="StartAnimation"
TargetObject="{Binding ElementName=SaturationBehavior}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Button>
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
using UI.Animations;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Navigation;

/// <summary>
/// A demonstration page of how you can use the Saturation effect using behaviors.
/// </summary>
public sealed partial class SaturationBehaviorPage
{
/// <summary>
/// Initializes a new instance of the <see cref="SaturationBehaviorPage"/> class.
/// </summary>
public SaturationBehaviorPage()
{
InitializeComponent();
}

/// <summary>
/// Invoked when the Page is loaded and becomes the current source of a parent Frame.
/// </summary>
/// <param name="e">Event data that can be examined by overriding code. The event data is representative of the pending navigation that will load the current Page. Usually the most relevant property to examine is Parameter.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

if (!AnimationExtensions.SaturationEffect.IsSupported)
{
WarningText.Visibility = Visibility.Visible;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Page
x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.BlurBehaviorPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages.OffsetBehavior"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Image x:Name="MyImage"
Source="ms-appx:///Assets/Photos/BigFourSummerHeat.jpg">
<interactivity:Interaction.Behaviors>
<behaviors:Saturation x:Name="SaturationBehavior"
Value="@[Value:DoubleSlider:1.0:0.0-1.0]"
Duration="@[Duration:DoubleSlider:3000.0:0.0-10000.0]"
Delay="@[Delay:DoubleSlider:0.0:0.0-5000.0]"
AutomaticallyStart="@[AutomaticallyStart:Bool:True]"/>
</interactivity:Interaction.Behaviors>
</Image>
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Bottom">
<Button Content="Apply" Margin="10">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:CallMethodAction TargetObject="{Binding ElementName=Saturation}" MethodName="StartAnimation"/>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Button>
</StackPanel>
</Grid>
</Page>
11 changes: 11 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@
"BadgeUpdateVersionRequired": "Anniversary Update required",
"DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/UWPCommunityToolkit/dev/docs/animations/Blur.md"
},
{
"Name": "Saturation",
"Type": "SaturationBehaviorPage",
"About": "Saturate XAML elements using composition",
"CodeUrl": "https://github.com/Microsoft/UWPCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors",
"CodeFile": "SaturationBehaviorCode.bind",
"XamlCodeFile": "SaturationBehaviorXaml.bind",
"Icon": "/SamplePages/Saturation/saturationBehavior.png",
"BadgeUpdateVersionRequired": "Anniversary Update required",
"DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/UWPCommunityToolkit/dev/docs/animations/Saturation.md"
},
{
"Name": "Light",
"Type": "LightBehaviorPage",
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Blur.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public double Value
/// </summary>
public override void StartAnimation()
{
if (AnimationExtensions.IsBlurSupported)
if (AnimationExtensions.BlurEffect.IsSupported)
{
_frameworkElement?.Blur(duration: Duration, delay: Delay, value: (float)Value)?.StartAsync();
}
Expand Down
68 changes: 68 additions & 0 deletions Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Saturation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

using Windows.UI.Xaml;

namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors
{
/// <summary>
/// A behavior to allow Saturation changes to a UI Element.
/// </summary>
public class Saturation : CompositionBehaviorBase
{
/// <summary>
/// The Saturation value of the associated object
/// </summary>
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value),
typeof(double), typeof(Saturation), new PropertyMetadata(0d, PropertyChangedCallback));

/// <summary>
/// The _framework element
/// </summary>
private FrameworkElement _frameworkElement;

/// <summary>
/// Gets or sets the Saturation.
/// </summary>
/// <value>
/// The Saturation.
/// </value>
public double Value
{
get { return (double) GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}

/// <summary>
/// Called after the behavior is attached to the <see cref="P:Microsoft.Xaml.Interactivity.Behavior.AssociatedObject" />.
/// </summary>
/// <remarks>
/// Override this to hook up functionality to the <see cref="P:Microsoft.Xaml.Interactivity.Behavior.AssociatedObject" />
/// </remarks>
protected override void OnAttached()
{
base.OnAttached();
_frameworkElement = AssociatedObject as FrameworkElement;
}

/// <summary>
/// Starts the animation.
/// </summary>
public override void StartAnimation()
{
if (AnimationExtensions.SaturationEffect.IsSupported)
{
_frameworkElement?.Saturation(duration: Duration, delay: Delay, value: (float) Value)?.StartAsync();
}
}
}
}
Loading

0 comments on commit c715b87

Please sign in to comment.