locked
How do you reference a control in the HubSection? RRS feed

  • Question

  • I have a Hub application. In the first HubSection I have an adControl that I want to hide when the user buys the app. I can't figure out how to do this though. Is there perhaps an alternative to doing this? 
    Friday, December 13, 2013 6:25 AM

Answers

  • Hi, Mark Moeykens.
    You can use Binding from viewModel, example:

    1. You have bool property in your viewModel (ex. IsFullVersion) which binding to visibility property in first hubSection

    private bool isFullVersion;
    
    public bool IsFullVersion
    { 
      get
      {
        return this.isFullVersion;
      }
    
      set
      {
        this.isFullVersion = value;
        RaisePropertyChanged("IsFullVersion");
      }
    }

    2. When you initialize your ViewModel set some value to this property

    this.IsFullVersion = [value];

    3. And in xaml binding property from viewModel to visibility property

    <HubSection Visibility = {Binding IsFullVersion, Convertor={StaticResource BooleanToVisibilityConverter}}>
      [Some Content]
    </HubSection>

    DataContext of page is current viewModel

    Regards, Nikita.

    • Marked as answer by Mark Moeykens Saturday, December 14, 2013 12:58 AM
    Friday, December 13, 2013 7:47 AM

All replies

  • Hi, Mark Moeykens.
    You can use Binding from viewModel, example:

    1. You have bool property in your viewModel (ex. IsFullVersion) which binding to visibility property in first hubSection

    private bool isFullVersion;
    
    public bool IsFullVersion
    { 
      get
      {
        return this.isFullVersion;
      }
    
      set
      {
        this.isFullVersion = value;
        RaisePropertyChanged("IsFullVersion");
      }
    }

    2. When you initialize your ViewModel set some value to this property

    this.IsFullVersion = [value];

    3. And in xaml binding property from viewModel to visibility property

    <HubSection Visibility = {Binding IsFullVersion, Convertor={StaticResource BooleanToVisibilityConverter}}>
      [Some Content]
    </HubSection>

    DataContext of page is current viewModel

    Regards, Nikita.

    • Marked as answer by Mark Moeykens Saturday, December 14, 2013 12:58 AM
    Friday, December 13, 2013 7:47 AM
  • Thank you, Nikita, this worked great!
    Saturday, December 14, 2013 12:59 AM