|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DynamicProxies;
using System.Reflection;
using System.Diagnostics;
namespace Sample.WPF
{
/// <summary>
/// Interaktionslogik für EditWindow.xaml
/// </summary>
public partial class EditWindow : Window
{
private bool _useProxy;
public EditWindow()
{
InitializeComponent();
}
public static bool Display(MyEntity entity, bool useProxy)
{
var window = new EditWindow();
window._useProxy = useProxy;
if (useProxy)
{
window.DataContext = new DataErrorInfoProxy(entity);
(window.DataContext as DataErrorInfoProxy).BeginEdit();
}
else
window.DataContext = entity;
var returnValue = window.ShowDialog();
if (useProxy)
{
if (returnValue.GetValueOrDefault(false))
(window.DataContext as DataErrorInfoProxy).EndEdit();
}
return returnValue.GetValueOrDefault(false);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (_useProxy)
{
var proxy = DataContext as DataErrorInfoProxy;
proxy.Validate();
this.FindBindingsRecursively(proxy);
if (proxy.HasErrors)
{
MessageBox.Show(this, proxy.Error, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
}
DialogResult = true;
Close();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (_useProxy)
{
var proxy = DataContext as DataErrorInfoProxy;
if (proxy.IsChanged)
{
switch (MessageBox.Show(this, "Do you want to save the data?", "Data changed", MessageBoxButton.YesNoCancel, MessageBoxImage.Question))
{
case MessageBoxResult.Yes: Button_Click(sender, e); return;
case MessageBoxResult.Cancel: return;
}
}
}
DialogResult = false;
Close();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.