diff --git a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml
index 961b43b7..baa1408f 100644
--- a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml
+++ b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml
@@ -11,30 +11,23 @@
d:DesignWidth="800">
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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 +39,96 @@
</Interactivity:Interaction.Behaviors>
</Rectangle>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DataTriggerBehavior performs an action when the data the behaviors is bound to meets a specified condition.
+ 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="DataTriggerEnumRectangle" Grid.Row="0" Fill="{StaticResource RoyalBlueBrush}" Stroke="{StaticResource HighlightBrush}" StrokeThickness="5">
+ <Interactivity:Interaction.Behaviors>
+ <Interactions:DataTriggerBehavior Binding="{Binding State}" Value="StateOne">
+ <Interactions:ChangePropertyAction PropertyName="Fill" Value="Red"/>
+ </Interactions:DataTriggerBehavior>
+ <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>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs b/samples/CS/XAMLBehaviorsSample/DataTriggerControl.xaml.cs
index 9f228cbf..25889a1f 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,51 @@
namespace XAMLBehaviorsSample
{
- public sealed partial class DataTriggerControl : UserControl
+
+ 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 = "")
+ {
+ PropertyChanged?.Invoke(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/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 };
+}
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)
{