public class MyObject : INotifyPropertyChanged
{
private string cityType;
public string Name
{
get { return name; }
set
{
name = value;
OnPropertyChanged("Name");
}
}
private string name;
public string CityType
{
get { return cityType; }
set
{
cityType = value;
OnPropertyChanged("CityType");
}
}
#region INotifyPropertyChanged Implementation
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
public partial class MainPage : UserControl, IPartImportsSatisfiedNotification
{
[Import]
public IDeploymentCatalogService CatalogService { get; set; }
public MainPage()
{
InitializeComponent();
CompositionInitializer.SatisfyImports(this);
}
[ImportMany(typeof(UserControl), AllowRecomposition=true)]
public UserControl[] Views { get; set; }
public void OnImportsSatisfied()
{
LayoutRoot.Children.Clear();
foreach (UserControl item in Views)
{
LayoutRoot.Children.Add(item);
}
}
}
[Import]
public IModalDialog ModalDialog
{
get;
set;
}
[Export(typeof(IModalDialog))]
public class ExtendedChildWindow : ChildWindow, IModalDialog
{
public void ShowDialog()
{
this.Width = 450;
this.Height = 300;
this.Show();
}
}
[ImportMany(AllowRecomposition = true)]
public IModalView[] Editors { get; set; }
this.ModalDialogWorker.ShowDialog(this.ModalDialog, view, o, dialog =>
{
if (this.ModalDialog.DialogResult.HasValue &&
this.ModalDialog.DialogResult.Value)
{
}
});
"" ModalDialogWorker, Calabonga.Silverlight.Framework:
namespace Calabonga.Silverlight.Framework
{
[Export(typeof(IModalDialogWorker))]
public class ModalDialogWorker : IModalDialogWorker
{
public void ShowDialog(IModalDialog modalDialog, IModalView modalView, T dataContext, Action onClosed)
{
if (modalDialog == null)
throw new ArgumentNullException("modalDialog", " null");
if (modalView == null)
throw new ArgumentNullException("modalView", " null");
EventHandler onDialogClosedHandler = null;
EventHandler onViewClosedHandler = null;
if (onClosed != null)
{
onDialogClosedHandler = (s, a) =>
{
modalDialog.Closed -= onDialogClosedHandler;
onClosed(dataContext);
};
onViewClosedHandler = (s, a) =>
{
modalDialog.Closed -= onDialogClosedHandler;
modalView.Closed -= onViewClosedHandler;
modalDialog.DialogResult = a.DialogResult;
onClosed(dataContext);
};
modalDialog.Closed += onDialogClosedHandler;
modalView.Closed += onViewClosedHandler;
}
modalDialog.Content = modalView;
modalView.DataContext = dataContext;
modalDialog.ShowDialog();
}
}
}
, "" .
MEF
(shell) "" ( ), Managed Extensibility Framework (MEF). MEF , :
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
, , . XAP-. , , (ExportAttribute), , FormExternal FormView:
[Export(typeof(UserControl))]
public partial class FormExternal : UserControl
{
public FormExternal()
{
InitializeComponent();
}
}
, , , , . (, , ...). () . View:
[ImportMany(typeof(UserControl), AllowRecomposition=true)]
public UserControl[] Views { get; set; }
:
AllowRecomposition=true
, MEF-. , . , . , , :
public MainPage()
{
InitializeComponent();
CompositionInitializer.SatisfyImports(this);
}
MEF- IPartImportsSatisfiedNotification, :
public void OnImportsSatisfied()
{
LayoutRoot.Children.Clear();
foreach (UserControl item in Views)
{
LayoutRoot.Children.Add(item);
}
}
. :
, "", CheckBox . :
private IModalView[] editors;
[ImportMany(AllowRecomposition = true)]
public IModalView[] Editors
{
get
{ return editors; }
set
{
editors = value;
checkEditor.IsEnabled = (this.Editors != null) && (this.Editors.Count() > 1);
OnPropertyChanged("Editors");
}
}
Code-Bihind ViewModel (MVVM) ( ), . , "" ... !!!
. , " " , , "" (. №3 AdvancedEditor).
private void Button_Click(object sender, RoutedEventArgs e)
{
CatalogService.AddXap("FormView.xap");
CatalogService.AddXap("AdvancedEditor.xap");
(sender as Button).IsEnabled = false;
}
, , ( ) , INotifyPropertyChanged.
: Memento .
, , CheckBox . , ( ) .
- . ! ?! !
Visual Studio 2010
this.ModalDialogWorker.ShowDialog(this.ModalDialog, view, o, dialog =>
{
if (this.ModalDialog.DialogResult.HasValue &&
this.ModalDialog.DialogResult.Value)
{
}
});
"" ModalDialogWorker, Calabonga.Silverlight.Framework:
namespace Calabonga.Silverlight.Framework
{
[Export(typeof(IModalDialogWorker))]
public class ModalDialogWorker : IModalDialogWorker
{
public void ShowDialog(IModalDialog modalDialog, IModalView modalView, T dataContext, Action onClosed)
{
if (modalDialog == null)
throw new ArgumentNullException("modalDialog", " null");
if (modalView == null)
throw new ArgumentNullException("modalView", " null");
EventHandler onDialogClosedHandler = null;
EventHandler onViewClosedHandler = null;
if (onClosed != null)
{
onDialogClosedHandler = (s, a) =>
{
modalDialog.Closed -= onDialogClosedHandler;
onClosed(dataContext);
};
onViewClosedHandler = (s, a) =>
{
modalDialog.Closed -= onDialogClosedHandler;
modalView.Closed -= onViewClosedHandler;
modalDialog.DialogResult = a.DialogResult;
onClosed(dataContext);
};
modalDialog.Closed += onDialogClosedHandler;
modalView.Closed += onViewClosedHandler;
}
modalDialog.Content = modalView;
modalView.DataContext = dataContext;
modalDialog.ShowDialog();
}
}
}
, "" .
MEF
(shell) "" ( ), Managed Extensibility Framework (MEF). MEF , :
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
, , . XAP-. , , (ExportAttribute), , FormExternal FormView:
[Export(typeof(UserControl))]
public partial class FormExternal : UserControl
{
public FormExternal()
{
InitializeComponent();
}
}
, , , , . (, , ...). () . View:
[ImportMany(typeof(UserControl), AllowRecomposition=true)]
public UserControl[] Views { get; set; }
:
AllowRecomposition=true
, MEF-. , . , . , , :
public MainPage()
{
InitializeComponent();
CompositionInitializer.SatisfyImports(this);
}
MEF- IPartImportsSatisfiedNotification, :
public void OnImportsSatisfied()
{
LayoutRoot.Children.Clear();
foreach (UserControl item in Views)
{
LayoutRoot.Children.Add(item);
}
}
. :
, "", CheckBox . :
private IModalView[] editors;
[ImportMany(AllowRecomposition = true)]
public IModalView[] Editors
{
get
{ return editors; }
set
{
editors = value;
checkEditor.IsEnabled = (this.Editors != null) && (this.Editors.Count() > 1);
OnPropertyChanged("Editors");
}
}
Code-Bihind ViewModel (MVVM) ( ), . , "" ... !!!
. , " " , , "" (. №3 AdvancedEditor).
private void Button_Click(object sender, RoutedEventArgs e)
{
CatalogService.AddXap("FormView.xap");
CatalogService.AddXap("AdvancedEditor.xap");
(sender as Button).IsEnabled = false;
}
, , ( ) , INotifyPropertyChanged.
: Memento .
, , CheckBox . , ( ) .
- . ! ?! !
Visual Studio 2010
this.ModalDialogWorker.ShowDialog(this.ModalDialog, view, o, dialog =>
{
if (this.ModalDialog.DialogResult.HasValue &&
this.ModalDialog.DialogResult.Value)
{
}
});
"" ModalDialogWorker, Calabonga.Silverlight.Framework:
namespace Calabonga.Silverlight.Framework
{
[Export(typeof(IModalDialogWorker))]
public class ModalDialogWorker : IModalDialogWorker
{
public void ShowDialog(IModalDialog modalDialog, IModalView modalView, T dataContext, Action onClosed)
{
if (modalDialog == null)
throw new ArgumentNullException("modalDialog", " null");
if (modalView == null)
throw new ArgumentNullException("modalView", " null");
EventHandler onDialogClosedHandler = null;
EventHandler onViewClosedHandler = null;
if (onClosed != null)
{
onDialogClosedHandler = (s, a) =>
{
modalDialog.Closed -= onDialogClosedHandler;
onClosed(dataContext);
};
onViewClosedHandler = (s, a) =>
{
modalDialog.Closed -= onDialogClosedHandler;
modalView.Closed -= onViewClosedHandler;
modalDialog.DialogResult = a.DialogResult;
onClosed(dataContext);
};
modalDialog.Closed += onDialogClosedHandler;
modalView.Closed += onViewClosedHandler;
}
modalDialog.Content = modalView;
modalView.DataContext = dataContext;
modalDialog.ShowDialog();
}
}
}
, "" .
MEF
(shell) "" ( ), Managed Extensibility Framework (MEF). MEF , :
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
, , . XAP-. , , (ExportAttribute), , FormExternal FormView:
[Export(typeof(UserControl))]
public partial class FormExternal : UserControl
{
public FormExternal()
{
InitializeComponent();
}
}
, , , , . (, , ...). () . View:
[ImportMany(typeof(UserControl), AllowRecomposition=true)]
public UserControl[] Views { get; set; }
:
AllowRecomposition=true
, MEF-. , . , . , , :
public MainPage()
{
InitializeComponent();
CompositionInitializer.SatisfyImports(this);
}
MEF- IPartImportsSatisfiedNotification, :
public void OnImportsSatisfied()
{
LayoutRoot.Children.Clear();
foreach (UserControl item in Views)
{
LayoutRoot.Children.Add(item);
}
}
. :
, "", CheckBox . :
private IModalView[] editors;
[ImportMany(AllowRecomposition = true)]
public IModalView[] Editors
{
get
{ return editors; }
set
{
editors = value;
checkEditor.IsEnabled = (this.Editors != null) && (this.Editors.Count() > 1);
OnPropertyChanged("Editors");
}
}
Code-Bihind ViewModel (MVVM) ( ), . , "" ... !!!
. , " " , , "" (. №3 AdvancedEditor).
private void Button_Click(object sender, RoutedEventArgs e)
{
CatalogService.AddXap("FormView.xap");
CatalogService.AddXap("AdvancedEditor.xap");
(sender as Button).IsEnabled = false;
}
, , ( ) , INotifyPropertyChanged.
: Memento .
, , CheckBox . , ( ) .
- . ! ?! !
Visual Studio 2010