locked
How to Binding the MainPage's variable in XAML

    Question


  • public sealed partial class MainPage : Page
    {
        public double StatusbarOpacity { get; set; }//Slider's value binding 
    
        public MainPage()
        {
            this.InitializeComponent();
        }
    }

    <Slider Value="{Binding StatusbarOpacity}" Maximum="100" Background="DarkOrange" BorderBrush="Red" Foreground="Blue" Header="Opacity" IntermediateValue="10"/>



    • Edited by oneonce Tuesday, March 10, 2015 3:07 PM
    Tuesday, March 10, 2015 3:06 PM

Answers

  • Set the DataContext of the MainPage to itself:

    public MainPage()
        {
            this.InitializeComponent();
            this.DataContext = this;
        }

    ...or Set the dataContext of the Slider:


    public MainPage()
        {
            this.InitializeComponent();
            slider.DataContext = this;
        }


    <Slider x:Name="slider" Value="{Binding StatusbarOpacity ...>

     


    Please remember to close your threads by marking helpful posts as answer and please start a new thread if you have a new question.

    • Proposed as answer by Dave SmitsMVP Tuesday, March 10, 2015 4:58 PM
    • Marked as answer by oneonce Wednesday, March 11, 2015 3:36 AM
    Tuesday, March 10, 2015 3:54 PM