Skip to content

Commit

Permalink
Updated to use ITriggerValue
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottIsAFool committed Aug 29, 2015
1 parent 73713b2 commit ec7cb9c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
42 changes: 36 additions & 6 deletions src/WindowsStateTriggers/HostedStateTrigger.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
using Windows.ApplicationModel.Core;
using System;
using Windows.ApplicationModel.Core;
using Windows.UI.Xaml;

namespace WindowsStateTriggers
{
/// <summary>
/// A state trigger for determining if the app is in a hosted state (for example, if share is being used)
/// </summary>
public class HostedStateTrigger : StateTriggerBase
public class HostedStateTrigger : StateTriggerBase, ITriggerValue
{
/// <summary>
/// Identifies the <see cref="IsHosted" /> dependency property.
/// </summary>
public static readonly DependencyProperty IsHostedProperty = DependencyProperty.Register(
"IsHosted", typeof (HostedState), typeof (HostedStateTrigger), new PropertyMetadata(HostedState.Unknown, OnIsHostedRequiredChanged));
"IsHosted", typeof(HostedState), typeof(HostedStateTrigger), new PropertyMetadata(HostedState.Unknown, OnIsHostedRequiredChanged));

/// <summary>
/// Gets or sets the is hosted value.
/// </summary>
public HostedState IsHosted
{
get { return (HostedState) GetValue(IsHostedProperty); }
get { return (HostedState)GetValue(IsHostedProperty); }
set { SetValue(IsHostedProperty, value); }
}

Expand All @@ -41,11 +42,11 @@ private void UpdateStateTrigger()
var isHosted = CoreApplication.GetCurrentView().IsHosted;
if (isHosted)
{
SetActive(IsHosted == HostedState.Hosted);
IsActive = IsHosted == HostedState.Hosted;
}
else
{
SetActive(IsHosted == HostedState.NotHosted);
IsActive = IsHosted == HostedState.NotHosted;
}
}

Expand All @@ -69,5 +70,34 @@ public enum HostedState
/// </summary>
NotHosted
}

#region ITriggerValue

private bool m_IsActive;

/// <summary>
/// Gets a value indicating whether this trigger is active.
/// </summary>
/// <value><c>true</c> if this trigger is active; otherwise, <c>false</c>.</value>
public bool IsActive
{
get { return m_IsActive; }
private set
{
if (m_IsActive != value)
{
m_IsActive = value;
base.SetActive(value);
IsActiveChanged?.Invoke(this, EventArgs.Empty);
}
}
}

/// <summary>
/// Occurs when the <see cref="IsActive" /> property has changed.
/// </summary>
public event EventHandler IsActiveChanged;

#endregion ITriggerValue
}
}
4 changes: 0 additions & 4 deletions src/WindowsStateTriggers/ITriggerValue.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsStateTriggers
{
Expand Down

0 comments on commit ec7cb9c

Please sign in to comment.