Last active
November 11, 2015 16:43
-
-
Save yuka1984/1f38158c3e95e46b5fa7 to your computer and use it in GitHub Desktop.
MaterialDesignInXAMLToolkitのDialogでコマンドのバインディングが外れてしまう ref: http://qiita.com/yu_ka1984/items/4b42872d751fe5522e5d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Button Command="{x:Static wpf:DialogHost.OpenDialogCommand}" HorizontalAlignment="Right" Margin="5,5,30,5" DockPanel.Dock="Bottom" Style="{StaticResource MaterialDesignFloatingActionAccentButton}"> | |
| <Button.CommandParameter> | |
| <StackPanel Margin="16"> | |
| <TextBlock>保存しますか?</TextBlock> | |
| <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" > | |
| <Button Style="{StaticResource MaterialDesignFlatButton}" | |
| IsDefault="True" | |
| Margin="0 8 8 0" | |
| Command="{Binding SaveCommand}" CommandParameter="{Binding Model}"> | |
| 保存 | |
| </Button> | |
| <Button Style="{StaticResource MaterialDesignFlatButton}" | |
| IsCancel="True" | |
| Margin="0 8 8 0" | |
| Command="wpf:DialogHost.CloseDialogCommand"> | |
| CANCEL | |
| </Button> | |
| </StackPanel> | |
| </StackPanel> | |
| </Button.CommandParameter> | |
| 保存 | |
| </Button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void OpenDialogHandler(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs) | |
| { | |
| if (executedRoutedEventArgs.Handled) return; | |
| var dependencyObject = executedRoutedEventArgs.OriginalSource as DependencyObject; | |
| if (dependencyObject != null) | |
| { | |
| _attachedDialogOpenedEventHandler = GetDialogOpenedAttached(dependencyObject); | |
| _attachedDialogClosingEventHandler = GetDialogClosingAttached(dependencyObject); | |
| } | |
| if (executedRoutedEventArgs.Parameter != null) | |
| { | |
| AssertTargetableContent(); | |
| DialogContent = executedRoutedEventArgs.Parameter; | |
| } | |
| SetCurrentValue(IsOpenProperty, true); | |
| executedRoutedEventArgs.Handled = true; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var dialogHomeSource = executedRoutedEventArgs.Source as FrameworkElement; | |
| if (dialogHomeSource?.DataContext != null | |
| && !DataContext.Equals(dialogHomeSource.DataContext)) | |
| { | |
| var dialogElement = DialogContent as FrameworkElement; | |
| if (dialogElement != null) | |
| { | |
| dialogElement.DataContext = dialogHomeSource.DataContext; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment