title: UWP windows 10 Visibility Binding to a global Variable
body: <p>I am trying to bind the visibility of a control to a Global variable:</p>
  <p>I have a Visibility Converter:</p>
  <pre class="lang-cs prettyprint-override"><code>public class BooleanToVisibilityConverter : IValueConverter
  {
      public bool IsReversed { get; set; }
  
      public object Convert(object value, Type targetType, object parameter, string language)
      {
          return (value is bool &amp;&amp; (bool)value) ? Visibility.Visible : Visibility.Collapsed;
      }
  
      public object ConvertBack(object value, Type targetType, object parameter, string language)
      {
          return value is Visibility &amp;&amp; (Visibility)value == Visibility.Visible;
      }
  }
  </code></pre>
  <p>I also created a class that inherits from DependencyObject:</p>
  <pre class="lang-cs prettyprint-override"><code>public class Verified : DependencyObject
  {
      public static readonly DependencyProperty VerifiedUserNameProperty = DependencyProperty.Register(
          &quot;VerifiedUserName&quot;,
          typeof(string),
          typeof(Verified),
          new PropertyMetadata(string.Empty)
      );
  
      public string VerifiedUserName
      {
          get { return (string)GetValue(VerifiedUserNameProperty); }
          set { SetValue(VerifiedUserNameProperty, value); }
      }
  
      public static readonly DependencyProperty IsVerifiedProperty = DependencyProperty.Register(
          &quot;IsVerified&quot;,
          typeof(bool),
          typeof(Verified),
          new PropertyMetadata(false, new PropertyChangedCallback(IsVerifiedChanged))
      );
  
      public bool IsVerified
      {
          get { return (bool)GetValue(IsVerifiedProperty); }
          set { SetValue(IsVerifiedProperty, value); }
      }
  
      private static void IsVerifiedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
          Verified container = d as Verified;
          bool latestIsVerifiedValue = (bool)e.NewValue;
          if (latestIsVerifiedValue == true)
          {
              //To Do
          }
      }
  }
  </code></pre>
  <p>in my App.xaml I created to variables:</p>
  <pre class="lang-cs prettyprint-override"><code>public static Verified myValidator = new Verified();
  
  public static BooleanToVisibilityConverter myConverter = new BooleanToVisibilityConverter();
  </code></pre>
  <p>In a simple page I added a text box and I want to bind it's Visibility to the myValidator variable.</p>
  <p>In order to accomplish that I am creating the binding in code:</p>
  <pre class="lang-cs prettyprint-override"><code>Binding myBinding = new Binding();
  myBinding.Source = App.myValidator;
  myBinding.Path = new PropertyPath(&quot;IsVerified&quot;);
  myBinding.Mode = BindingMode.OneWay;
  myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
  myBinding.Converter = App.myConverter;
  BindingOperations.SetBinding(txtName2, VisibilityProperty, myBinding);
  </code></pre>
  <p>In the App.xaml: I am setting the value of my Validator this way :</p>
  <pre class="lang-cs prettyprint-override"><code>App.myValidator.IsVerified = false;
  </code></pre>
  <p>When I navigate to the simple page the text box is not visible (OK).</p>
  <p>To test the behavior, I added a button on my screen and added code to change the value of myValidator.isVerified.</p>
  <p>As I change the value of my App.myValidator.IsVerified the visibility of the textbox does not change. How can I solve the problem?</p>