diff --git a/FeatureflowExample.sln b/FeatureflowExample.sln index 34350da..871c16c 100644 --- a/FeatureflowExample.sln +++ b/FeatureflowExample.sln @@ -6,8 +6,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureflowExample", "Featu EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureflowWpfExample", "FeatureflowWpfExample\FeatureflowWpfExample.csproj", "{AF38CDE1-EF0F-4306-AFAF-7BD89D2D0B5B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Featureflow", "..\featureflow-dotnet-client\Featureflow\Featureflow.csproj", "{F4D323C7-0600-4E1E-9D3B-407904A7B3AA}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -22,10 +20,6 @@ Global {AF38CDE1-EF0F-4306-AFAF-7BD89D2D0B5B}.Debug|Any CPU.Build.0 = Debug|Any CPU {AF38CDE1-EF0F-4306-AFAF-7BD89D2D0B5B}.Release|Any CPU.ActiveCfg = Release|Any CPU {AF38CDE1-EF0F-4306-AFAF-7BD89D2D0B5B}.Release|Any CPU.Build.0 = Release|Any CPU - {F4D323C7-0600-4E1E-9D3B-407904A7B3AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F4D323C7-0600-4E1E-9D3B-407904A7B3AA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F4D323C7-0600-4E1E-9D3B-407904A7B3AA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F4D323C7-0600-4E1E-9D3B-407904A7B3AA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FeatureflowWpfExample/Converters/ExampleToViewConverter.cs b/FeatureflowWpfExample/Converters/ExampleToViewConverter.cs index 598c44e..79ae74d 100644 --- a/FeatureflowWpfExample/Converters/ExampleToViewConverter.cs +++ b/FeatureflowWpfExample/Converters/ExampleToViewConverter.cs @@ -25,6 +25,10 @@ public object Convert(object value, Type targetType, object parameter, CultureIn case ExampleTag.SimpleSwitch: pathToXaml = "Views/SimpleSwitchPage.xaml"; break; + + case ExampleTag.TrafficLight: + pathToXaml = "Views/TrafficLightPage.xaml"; + break; } if (pathToXaml != null) diff --git a/FeatureflowWpfExample/FeatureflowWpfExample.csproj b/FeatureflowWpfExample/FeatureflowWpfExample.csproj index 3abd3d1..882f5cb 100644 --- a/FeatureflowWpfExample/FeatureflowWpfExample.csproj +++ b/FeatureflowWpfExample/FeatureflowWpfExample.csproj @@ -62,6 +62,9 @@ SimpleSwitchPage.xaml + + TrafficLightPage.xaml + MSBuild:Compile Designer @@ -81,6 +84,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + @@ -108,11 +115,5 @@ - - - {f4d323c7-0600-4e1e-9d3b-407904a7b3aa} - Featureflow - - \ No newline at end of file diff --git a/FeatureflowWpfExample/Views/TrafficLightPage.xaml b/FeatureflowWpfExample/Views/TrafficLightPage.xaml new file mode 100644 index 0000000..dc42843 --- /dev/null +++ b/FeatureflowWpfExample/Views/TrafficLightPage.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + This example displays that the feature can contains more than two values. In our case the feature named + color-set + have three values: 'red', 'yellow' and 'green'. + + You can create different rules to manage them all in your + featureflow.io + account. Selected color displays current feature value. + + + + + + + + + + + + + + + + + + + + + diff --git a/FeatureflowWpfExample/Views/TrafficLightPage.xaml.cs b/FeatureflowWpfExample/Views/TrafficLightPage.xaml.cs new file mode 100644 index 0000000..4bf0ecc --- /dev/null +++ b/FeatureflowWpfExample/Views/TrafficLightPage.xaml.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace FeatureflowWpfExample.Views +{ + /// + /// Interaction logic for TrafficLightView.xaml + /// + public partial class TrafficLightView : BaseExamplePage + { + public const string ExampleFeatureKey = "color-set"; + + public TrafficLightView() + { + InitializeComponent(); + } + + protected override void Activate() + { + base.Activate(); + FeatureflowClientProvider.GetClient().FeatureUpdated += Client_FeatureUpdated; + UpdateFeatureValue(); + } + + public ColorFeature[] Colors { get; } = new ColorFeature[] + { + new ColorFeature{ Color = "red" }, + new ColorFeature{ Color = "yellow" }, + new ColorFeature{ Color = "green" }, + }; + + protected override void Deactivate() + { + FeatureflowClientProvider.GetClient().FeatureUpdated -= Client_FeatureUpdated; + base.Deactivate(); + } + + private void Client_FeatureUpdated(Featureflow.Client.IFeatureflowClient sender, Featureflow.Client.FeatureUpdatedEventArgs args) + { + if (args.FeatureKey == ExampleFeatureKey) + { + UpdateFeatureValue(); + } + } + + private void UpdateFeatureValue() + { + Dispatcher.InvokeAsync(() => + { + string value = FeatureflowClientProvider.GetClient().Evaluate(ExampleFeatureKey).Value(); + foreach (var color in Colors) + { + color.IsSelected = color.Color == value; + } + }); + } + } + + public class ColorFeature + : DependencyObject + { + public static DependencyProperty IsSelectedProperty = + DependencyProperty.Register("IsSelected", typeof(bool), typeof(ColorFeature)); + + public string Color { get; set; } + + public bool IsSelected + { + get { return (bool)GetValue(IsSelectedProperty); } + set { SetValue(IsSelectedProperty, value); } + } + } +}