Skip to content

Instantly share code, notes, and snippets.

@yuka1984
Last active November 11, 2015 16:43
Show Gist options
  • Select an option

  • Save yuka1984/1f38158c3e95e46b5fa7 to your computer and use it in GitHub Desktop.

Select an option

Save yuka1984/1f38158c3e95e46b5fa7 to your computer and use it in GitHub Desktop.
MaterialDesignInXAMLToolkitのDialogでコマンドのバインディングが外れてしまう ref: http://qiita.com/yu_ka1984/items/4b42872d751fe5522e5d
<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>
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;
}
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