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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Bind DelegateCommand from window and page on that window

Thread ID:

Created:

Updated:

Platform:

Replies:

123405 Mar 15,2016 09:53 AM UTC Mar 17,2016 04:22 AM UTC WPF 3
loading
Tags: SfDataGrid
Valery Piashchynski
Asked On March 15, 2016 09:53 AM UTC

Hello
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" />
</Grid>

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}"
                          CommandParameter="ShowColumnChooser"
                          Content="ShowColumnChooser"
                          IsChecked="{Binding ShowColumnChooser}" />

In MainWindow i have Behaviors:
    <intty:Interaction.Behaviors>
        <local:MainWindowBehaviour />
    </intty:Interaction.Behaviors>

In Behavior i have following code:

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

        private void InitializeColumnChooserPopup()
        {
            _chooserWindow = new ColumnChooser(AssociatedObject.GwMain);
            _chooserWindow.Resources.MergedDictionaries.Clear();
            _chooserWindow.ClearValue(FrameworkElement.StyleProperty);
            _chooserWindow.Resources.MergedDictionaries.Add(AssociatedObject.GwMain.Resources.MergedDictionaries[0]);
            AssociatedObject.GwMain.GridColumnDragDropController = new GridColumnChooserController(AssociatedObject.GwMain,_chooserWindow);
            _chooserWindow.Width = 300;
            _chooserWindow.Height = 600;
            _chooserWindow.AllowsTransparency = true;
            _chooserWindow.Show();
            _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?




Jai Ganesh S [Syncfusion]
Replied On 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);

     window.Show();

}


public partial class Window1 : Window

    {

        public Window1(object data)

        {

            InitializeComponent();

            this.DataContext = data;

        }

    }


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


Regards

Jai Ganesh S


Valery Piashchynski
Replied On 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.

Jai Ganesh S [Syncfusion]
Replied On 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.


Regards

Jai Ganesh S



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;