locked
CommandBar IsOpen={Binding} does not work RRS feed

  • Question

  • Hello everybody,

    I want to bind the property "IsOpen" of a CommandBar to a bool value of my ViewModel.

    However even this simple version does not work:

    <CommandBar x:Name="CommandBar1" IsOpen="{Binding}">

    and in CodeBehind:

    CommandBar1.DataContext = true;

    Of course, this is a very simple example, but in my opinion this should work, so that the CommandBar is shown.

    A direct

    CommandBar1.IsOpen = true;

    works fine . . .

    Thank you very much in advance!


    • Edited by Klaus Schulz Thursday, January 2, 2014 12:08 PM typo
    Thursday, January 2, 2014 12:03 PM

Answers

  • its an timing issue. try to set the datacontext in the page load event

    public MainPage()
            {
                this.InitializeComponent();
                this.Loaded += MainPage_Loaded;
            }
    
            void MainPage_Loaded(object sender, RoutedEventArgs e)
            {
                CommandBar1.DataContext = true;
            }


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by Klaus Schulz Thursday, January 2, 2014 2:54 PM
    Thursday, January 2, 2014 2:15 PM

All replies

  • its an timing issue. try to set the datacontext in the page load event

    public MainPage()
            {
                this.InitializeComponent();
                this.Loaded += MainPage_Loaded;
            }
    
            void MainPage_Loaded(object sender, RoutedEventArgs e)
            {
                CommandBar1.DataContext = true;
            }


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by Klaus Schulz Thursday, January 2, 2014 2:54 PM
    Thursday, January 2, 2014 2:15 PM
  • Thank you very much! That solved the issue.
    Thursday, January 2, 2014 2:54 PM