We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Bind DelegateCommand from window and page on that window

I have a window (for example MainWindow), in that window situated SfDataGrid in Row 1, ond page, on Row 2:

<Grid Grid.Row="2">
            <Frame Source="MainButtonsBar.xaml" NavigationUIVisibility="Hidden" />

Scheme of windows is following MainWindow.xaml->MainButtonsBar.xaml -> Page1
                                                                                                                         -> Page2

MainButtonsBar.xaml contains ToggleButton:
<ToggleButton x:Name="ShowColumnChooser" Grid.Row="0" Grid.Column="1"
                          Command="{Binding ColumnChooserCommand}"
                          IsChecked="{Binding ShowColumnChooser}" />

In MainWindow i have Behaviors:
        <local:MainWindowBehaviour />

In Behavior i have following code:

            _mainWindowViewModel = (AssociatedObject.DataContext) as MainWindowViewModel;
            if (_mainWindowViewModel != null)
                _mainWindowViewModel.ColumnChooserCommand = new DelegateCommand<object>(ColumnChooserCommandHandler);

        private void InitializeColumnChooserPopup()
            _chooserWindow = new ColumnChooser(AssociatedObject.GwMain);
            AssociatedObject.GwMain.GridColumnDragDropController = new GridColumnChooserController(AssociatedObject.GwMain,_chooserWindow);
            _chooserWindow.Width = 300;
            _chooserWindow.Height = 600;
            _chooserWindow.AllowsTransparency = true;
            _chooserWindow.Owner = AssociatedObject;
            _chooserWindow.Closing += ChooserWindow_Closing;

When i click in that button i want to show ColumnChooser of SfDataGrid situated on MainWindow, but they not shown. Only when MainWindow fist time load triggers _chooserWindow.Show(); and ColumnChooser shows (only ones) and if i close it, columnChooser not shown by pressing button. If i place ToggleButton directly on MainWindow, all Ok and DelegateCommant route to nested event and i can open-close ColumnChooser multiply times.
Can you help me with that problem?

3 Replies

JG Jai Ganesh S Syncfusion Team March 16, 2016 01:54 PM UTC

Hi Valery,

You can achieve your requirement for enable or disable the ColumnChooser window from another window by setting the DataContext for that window like the below code example,

private void Button_Click(object sender, RoutedEventArgs e)


     Window1 window = new Window1(this.DataContext);



public partial class Window1 : Window


        public Window1(object data)



            this.DataContext = data;



Sample: http://www.syncfusion.com/downloads/support/directtrac/153710/ze/ColumnChooserDemo1022689704


Jai Ganesh S

VP Valery Piashchynski March 16, 2016 05:25 PM UTC

Thank you for you answer, but problem in that i can not directly invoke window because button situated in page. Other words, i cant add dataContex by that way. Window in MainWindow is just contaider for pages. I try to set dataContex of MainWindow to parent in XAML, but its not working. Simply, than i try to set DataContex by foolowing code and all working:
this.DataContext = Application.Current.Windows.OfType<MainWindow>().Single().DataContext; (in ctor of child window)
First datacontex -> this is datacontex of child window with pages
Second -> Parent window
Thank you.

JG Jai Ganesh S Syncfusion Team March 17, 2016 04:22 AM UTC

Hi Valery,

Thank you for the update.

Please let us know if you need further assistance on this.


Jai Ganesh S

Live Chat Icon For mobile
Up arrow icon