From 6341f28f08832d97b2cb3b3d856b39c5ef128d6d Mon Sep 17 00:00:00 2001
From: "Patrick M. Decoster"
Date: Tue, 23 Apr 2019 18:45:12 +0200
Subject: [PATCH 1/8] Split DataTrigger Sample into GreaterThan and Enum
section. Implemented DataTrigger with Enum sample
---
.../DataTriggerControl.xaml | 145 ++++++++++++------
.../DataTriggerControl.xaml.cs | 48 +++++-
.../XAMLBehaviorsSample.csproj | 14 +-
samples/CS/XAMLBehaviorsSample/project.json | 16 --
4 files changed, 156 insertions(+), 67 deletions(-)
delete mode 100644 samples/CS/XAMLBehaviorsSample/project.json
diff --git a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml
index 961b43b7..e5f73c4c 100644
--- a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml
+++ b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml
@@ -11,30 +11,74 @@
d:DesignWidth="800">
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+ DataTriggerBehavior performs an action when the data the behaviors is bound to meets a specified condition.
+ In this example, when the bound data of the slider's value reaches above 50, the behavior triggers an action to change the color of the rectangle.
+
+
+
+ <Rectangle x:Name="DataTriggerRectangle">
+ <Interactivity:Interaction.Behaviors>
+ <Interactions:DataTriggerBehavior Binding="{Binding Value, ElementName=slider}" ComparisonCondition="GreaterThan" Value="50">
+ <Interactions:ChangePropertyAction TargetObject="{Binding ElementName=DataTriggerRectangle}" PropertyName="Fill" Value="{StaticResource PaleYellowBrush}"/>
+ </Interactions:DataTriggerBehavior>
+ <Interactions:DataTriggerBehavior Binding="{Binding Value, ElementName=slider}" ComparisonCondition="LessThanOrEqual" Value="50">
+ <Interactions:ChangePropertyAction TargetObject="{Binding ElementName=DataTriggerRectangle}" PropertyName="Fill" Value="{StaticResource RoyalBlueBrush}"/>
+ </Interactions:DataTriggerBehavior>
+ </Interactivity:Interaction.Behaviors>
+</Rectangle>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
- DataTriggerBehavior performs an action when the data the behaviors is bound to meets a specified condition.
+
+
+
+
+ DataTriggerBehavior performs an action when the data the behaviors is bound to meets a specified condition.
In this example, when the bound data of the slider's value reaches above 50, the behavior triggers an action to change the color of the rectangle.
-
-
-
+
+
+
<Rectangle x:Name="DataTriggerRectangle">
<Interactivity:Interaction.Behaviors>
<Interactions:DataTriggerBehavior Binding="{Binding Value, ElementName=slider}" ComparisonCondition="GreaterThan" Value="50">
@@ -46,29 +90,42 @@
</Interactivity:Interaction.Behaviors>
</Rectangle>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
index 9f228cbf..a195b275 100644
--- a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
+++ b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.IO;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
@@ -17,11 +19,55 @@
namespace XAMLBehaviorsSample
{
- public sealed partial class DataTriggerControl : UserControl
+ public enum StateEnum { StateOne, StateTwo, StateThree };
+ public sealed partial class DataTriggerControl : UserControl, INotifyPropertyChanged
{
+ private StateEnum _state;
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ // This method is called by the Set accessor of each property.
+ // The CallerMemberName attribute that is applied to the optional propertyName
+ // parameter causes the property name of the caller to be substituted as an argument.
+ private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
+ {
+ if (PropertyChanged != null)
+ {
+ PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
+ public StateEnum State {
+ get
+ {
+ return _state;
+ }
+ set
+ {
+ _state = value;
+ NotifyPropertyChanged();
+
+ }
+ }
+
public DataTriggerControl()
{
this.InitializeComponent();
+ this.DataContext = this;
+ }
+
+ private void B1_Click(object sender, RoutedEventArgs e)
+ {
+ this.State = StateEnum.StateOne;
+ }
+
+ private void B2_Click(object sender, RoutedEventArgs e)
+ {
+ this.State = StateEnum.StateTwo;
+ }
+
+ private void B3_Click(object sender, RoutedEventArgs e)
+ {
+ this.State = StateEnum.StateThree;
}
}
}
diff --git a/samples/CS/XAMLBehaviorsSample/XAMLBehaviorsSample.csproj b/samples/CS/XAMLBehaviorsSample/XAMLBehaviorsSample.csproj
index 7b288e3c..b106d29c 100644
--- a/samples/CS/XAMLBehaviorsSample/XAMLBehaviorsSample.csproj
+++ b/samples/CS/XAMLBehaviorsSample/XAMLBehaviorsSample.csproj
@@ -11,14 +11,15 @@
XAMLBehaviorsSample
en-US
UAP
- 10.0.10240.0
- 10.0.10240.0
+ 10.0.17134.0
+ 10.0.17134.0
14
true
512
{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
XAMLBehaviorsSample_TemporaryKey.pfx
A59F5EC5577FD12DC7C715F9B786ED18FE397750
+ win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot
true
@@ -89,10 +90,6 @@
true
true
-
-
-
-
App.xaml
@@ -308,6 +305,11 @@
Microsoft.Xaml.Interactivity
+
+
+ 5.0.0
+
+
14.0
diff --git a/samples/CS/XAMLBehaviorsSample/project.json b/samples/CS/XAMLBehaviorsSample/project.json
deleted file mode 100644
index c5949392..00000000
--- a/samples/CS/XAMLBehaviorsSample/project.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "dependencies": {
- "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
- },
- "frameworks": {
- "uap10.0": {}
- },
- "runtimes": {
- "win10-arm": {},
- "win10-arm-aot": {},
- "win10-x86": {},
- "win10-x86-aot": {},
- "win10-x64": {},
- "win10-x64-aot": {}
- }
-}
\ No newline at end of file
From 100a6e35d0ef1e88589175397cc0240d86a527e9 Mon Sep 17 00:00:00 2001
From: "Patrick M. Decoster"
Date: Tue, 23 Apr 2019 18:48:18 +0200
Subject: [PATCH 2/8] Implemented Enum support for DataTriggerBehavior.
---
.../Core/DataTriggerBehavior.cs | 2 +-
.../Core/TypeConverterHelper.cs | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Core/DataTriggerBehavior.cs b/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Core/DataTriggerBehavior.cs
index 9bd31b9f..b68e2db3 100644
--- a/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Core/DataTriggerBehavior.cs
+++ b/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Core/DataTriggerBehavior.cs
@@ -93,7 +93,7 @@ private static bool Compare(object leftOperand, ComparisonConditionType operator
{
if (leftOperand != null && rightOperand != null)
{
- rightOperand = TypeConverterHelper.Convert(rightOperand.ToString(), leftOperand.GetType().FullName);
+ rightOperand = TypeConverterHelper.Convert(rightOperand.ToString(), leftOperand.GetType());
}
IComparable leftComparableOperand = leftOperand as IComparable;
diff --git a/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Core/TypeConverterHelper.cs b/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Core/TypeConverterHelper.cs
index ec32299c..55e6643f 100644
--- a/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Core/TypeConverterHelper.cs
+++ b/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Core/TypeConverterHelper.cs
@@ -7,6 +7,7 @@ namespace Microsoft.Xaml.Interactions.Core
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;
using Interactivity;
+ using System.Reflection;
///
/// A helper class that enables converting values specified in markup (strings) to their object representation.
@@ -63,6 +64,15 @@ public static Object Convert(string value, string destinationTypeFullName)
return null;
}
+ public static Object Convert(string value, Type destinationType)
+ {
+ var typeInfo = destinationType.GetTypeInfo();
+
+ if (typeInfo.IsEnum)
+ return Enum.Parse(destinationType, value);
+
+ return Convert(value, destinationType.FullName);
+ }
private static String GetScope(string name)
{
From 87b524f31b5f4404d39803f87905362dd152c410 Mon Sep 17 00:00:00 2001
From: "Patrick M. Decoster"
Date: Tue, 23 Apr 2019 19:29:58 +0200
Subject: [PATCH 3/8] Reverted changes to XAMLBehaviorsSample.csproj
---
.../XAMLBehaviorsSample/XAMLBehaviorsSample.csproj | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/samples/CS/XAMLBehaviorsSample/XAMLBehaviorsSample.csproj b/samples/CS/XAMLBehaviorsSample/XAMLBehaviorsSample.csproj
index b106d29c..7b288e3c 100644
--- a/samples/CS/XAMLBehaviorsSample/XAMLBehaviorsSample.csproj
+++ b/samples/CS/XAMLBehaviorsSample/XAMLBehaviorsSample.csproj
@@ -11,15 +11,14 @@
XAMLBehaviorsSample
en-US
UAP
- 10.0.17134.0
- 10.0.17134.0
+ 10.0.10240.0
+ 10.0.10240.0
14
true
512
{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
XAMLBehaviorsSample_TemporaryKey.pfx
A59F5EC5577FD12DC7C715F9B786ED18FE397750
- win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot
true
@@ -90,6 +89,10 @@
true
true
+
+
+
+
App.xaml
@@ -305,11 +308,6 @@
Microsoft.Xaml.Interactivity
-
-
- 5.0.0
-
-
14.0
From a24d1ee6cf9443de54a63c85513605b3b9f7be21 Mon Sep 17 00:00:00 2001
From: "Patrick M. Decoster"
Date: Tue, 23 Apr 2019 19:33:30 +0200
Subject: [PATCH 4/8] Reverted deletion of project.json
---
samples/CS/XAMLBehaviorsSample/project.json | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
create mode 100644 samples/CS/XAMLBehaviorsSample/project.json
diff --git a/samples/CS/XAMLBehaviorsSample/project.json b/samples/CS/XAMLBehaviorsSample/project.json
new file mode 100644
index 00000000..c5949392
--- /dev/null
+++ b/samples/CS/XAMLBehaviorsSample/project.json
@@ -0,0 +1,16 @@
+{
+ "dependencies": {
+ "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
+ },
+ "frameworks": {
+ "uap10.0": {}
+ },
+ "runtimes": {
+ "win10-arm": {},
+ "win10-arm-aot": {},
+ "win10-x86": {},
+ "win10-x86-aot": {},
+ "win10-x64": {},
+ "win10-x64-aot": {}
+ }
+}
\ No newline at end of file
From 003f9d7b74649c7784d652ad35db09b00f940be8 Mon Sep 17 00:00:00 2001
From: "Patrick M. Decoster"
Date: Tue, 23 Apr 2019 19:57:34 +0200
Subject: [PATCH 5/8] Changed Sample Description for DataTriggerBehavior|Enum
Changed Column distribution for DataTriggerBehavior|Enum
---
.../XAMLBehaviorsSample/DataTriggerControl.xaml | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml
index e5f73c4c..baa1408f 100644
--- a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml
+++ b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml
@@ -67,7 +67,7 @@
-
+
@@ -75,17 +75,20 @@
DataTriggerBehavior performs an action when the data the behaviors is bound to meets a specified condition.
- In this example, when the bound data of the slider's value reaches above 50, the behavior triggers an action to change the color of the rectangle.
+ In this example, when the bound enum changes its value, the behavior triggers an action to change the color of the rectangle based on which enum value it equals to.
- <Rectangle x:Name="DataTriggerRectangle">
+ <Rectangle x:Name="DataTriggerEnumRectangle" Grid.Row="0" Fill="{StaticResource RoyalBlueBrush}" Stroke="{StaticResource HighlightBrush}" StrokeThickness="5">
<Interactivity:Interaction.Behaviors>
- <Interactions:DataTriggerBehavior Binding="{Binding Value, ElementName=slider}" ComparisonCondition="GreaterThan" Value="50">
- <Interactions:ChangePropertyAction TargetObject="{Binding ElementName=DataTriggerRectangle}" PropertyName="Fill" Value="{StaticResource PaleYellowBrush}"/>
+ <Interactions:DataTriggerBehavior Binding="{Binding State}" Value="StateOne">
+ <Interactions:ChangePropertyAction PropertyName="Fill" Value="Red"/>
</Interactions:DataTriggerBehavior>
- <Interactions:DataTriggerBehavior Binding="{Binding Value, ElementName=slider}" ComparisonCondition="LessThanOrEqual" Value="50">
- <Interactions:ChangePropertyAction TargetObject="{Binding ElementName=DataTriggerRectangle}" PropertyName="Fill" Value="{StaticResource RoyalBlueBrush}"/>
+ <Interactions:DataTriggerBehavior Binding="{Binding State}" Value="StateTwo">
+ <Interactions:ChangePropertyAction PropertyName="Fill" Value="Green"/>
+ </Interactions:DataTriggerBehavior>
+ <Interactions:DataTriggerBehavior Binding="{Binding State}" Value="StateThree">
+ <Interactions:ChangePropertyAction PropertyName="Fill" Value="Blue"/>
</Interactions:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Rectangle>
From 58a9581e75130b7193ceabffd1b3b8278b1bacbe Mon Sep 17 00:00:00 2001
From: "Patrick M. Decoster"
Date: Fri, 17 May 2019 10:00:55 +0200
Subject: [PATCH 6/8] Placed StateEnum in a new file
---
.../CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs | 2 +-
samples/CS/XAMLBehaviorsSample/StateEnum.cs | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
create mode 100644 samples/CS/XAMLBehaviorsSample/StateEnum.cs
diff --git a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
index a195b275..7352d620 100644
--- a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
+++ b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
@@ -19,7 +19,7 @@
namespace XAMLBehaviorsSample
{
- public enum StateEnum { StateOne, StateTwo, StateThree };
+
public sealed partial class DataTriggerControl : UserControl, INotifyPropertyChanged
{
private StateEnum _state;
diff --git a/samples/CS/XAMLBehaviorsSample/StateEnum.cs b/samples/CS/XAMLBehaviorsSample/StateEnum.cs
new file mode 100644
index 00000000..08716bd1
--- /dev/null
+++ b/samples/CS/XAMLBehaviorsSample/StateEnum.cs
@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace XAMLBehaviorsSample
+{
+ public enum StateEnum { StateOne, StateTwo, StateThree };
+}
From ff34408e679eb4b0e4a6d534e7829c5be536ae2c Mon Sep 17 00:00:00 2001
From: "Patrick M. Decoster"
Date: Fri, 17 May 2019 10:01:59 +0200
Subject: [PATCH 7/8] Changed PropertyChanged handler to be thread-safe.
---
samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
index 7352d620..26f0004b 100644
--- a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
+++ b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
@@ -30,10 +30,7 @@ public sealed partial class DataTriggerControl : UserControl, INotifyPropertyCha
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public StateEnum State {
From 214d85d8f09127b56d7dd5d52a040672f0acd637 Mon Sep 17 00:00:00 2001
From: "Patrick M. Decoster"
Date: Fri, 17 May 2019 10:02:53 +0200
Subject: [PATCH 8/8] Removed empty space
---
samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs | 1 -
1 file changed, 1 deletion(-)
diff --git a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
index 26f0004b..25889a1f 100644
--- a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
+++ b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
@@ -42,7 +42,6 @@ public StateEnum State {
{
_state = value;
NotifyPropertyChanged();
-
}
}