I have a dialog that use, that i simple can't understand why it will not bind.
I use Joe White's DialogCloser, from this answer
public static class DialogCloser
{
public static readonly DependencyProperty DialogResultProperty =
DependencyProperty.RegisterAttached(
"DialogResult",
typeof(bool?),
typeof(DialogCloser),
new PropertyMetadata(DialogResultChanged));
private static void DialogResultChanged(
DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
var window = d as Window;
if (window != null)
window.DialogResult = e.NewValue as bool?;
}
public static void SetDialogResult(Window target, bool? value)
{
target.SetValue(DialogResultProperty, value);
}
}
I use it only in DialogWindow.xml
<Window x:Class="ATS.Views.Common.DialogWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="WindowDialog"
WindowStyle="SingleBorderWindow"
WindowStartupLocation="CenterOwner" SizeToContent="WidthAndHeight"
xmlns:xc="clr-namespace:ATS.Views.Common"
xc:DialogCloser.DialogResult="{Binding DialogResult}"
ResizeMode="NoResize">
<ContentPresenter x:Name="DialogPresenter" Content="{Binding .}"></ContentPresenter>
The Binding it self is on a abstract class that I want to use for dialog windows.
public class DialogViewModel : BaseViewModel
{
private bool? dialogResult;
public bool? DialogResult
{
get
{
return dialogResult;
}
set
{
dialogResult = value;
NotifyPropertyChange("DialogResult");
}
}
}
I open dialogs from ViewModels with this:
public bool? ShowDialog(string title, DialogViewModel dataContext)
{
var win = new DialogWindow();
win.Title = title;
win.DataContext = dataContext;
return win.ShowDialog();
}
Now what seems to happen, even tho i create new dialog windows, is that the binding it self only get added once, and therefor it will only work on the first dialog that is created.
Is it something to do with binding to an abstact class that makes the bindings not work, due to same namespace and names?
Edit: Ended up using Mark's way of handling dialog boxes, which can be found here