-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1021 from shenchauhan/effects
Adding saturation and a simpler way to add more effects
- Loading branch information
Showing
18 changed files
with
714 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+3.16 KB
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Saturation/SaturationBehavior.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions
8
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Saturation/SaturationBehaviorCode.bind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
46 changes: 46 additions & 0 deletions
46
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Saturation/SaturationBehaviorPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
46 changes: 46 additions & 0 deletions
46
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Saturation/SaturationBehaviorPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Saturation/SaturationBehaviorXaml.bind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Saturation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.