|
using System;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel.Composition;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using IssueVision.Common;
namespace IssueVision.Client
{
public partial class MyIssues : UserControl, ICleanup
{
#region "Private Data Members"
private const double MinimumWidth = 640;
private Lazy<ViewModelBase> _viewModelExport;
#endregion "Private Data Members"
#region "Constructor"
public MyIssues()
{
InitializeComponent();
// add the IssueEditor
issueEditorContentControl.Content = new IssueEditor();
// initialize the UserControl Width & Height
this.Content_Resized(this, null);
// register any AppMessages here
if (!ViewModelBase.IsInDesignModeStatic)
{
// Use MEF To load the View Model
_viewModelExport = App.Container.GetExport<ViewModelBase>(
ViewModelTypes.MyIssuesViewModel);
this.DataContext = _viewModelExport.Value;
}
}
#endregion "Constructor"
#region "Logic to dynamically set UserControl Width and Height"
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
}
private void UserControl_Unloaded(object sender, RoutedEventArgs e)
{
App.Current.Host.Content.Resized -= new EventHandler(Content_Resized);
}
private void Content_Resized(object sender, EventArgs e)
{
// stretch the UserControl to the current browser width if wider than MinimumWidth
if (App.Current.Host.Content.ActualWidth < MinimumWidth)
this.Width = MinimumWidth;
else
this.Width = App.Current.Host.Content.ActualWidth;
// stretch the UserControl to the current brower Height - Title Height(42) - Menu Height(22)
this.Height = App.Current.Host.Content.ActualHeight - 42 - 22;
}
#endregion "Logic to dynamically set UserControl Width and Height"
#region "ICleanup interface implementation"
public void Cleanup()
{
// call Cleanup on its ViewModel
((ICleanup)this.DataContext).Cleanup();
// call Cleanup on IssueEditor
ICleanup issueEditor = this.issueEditorContentControl.Content as ICleanup;
if (issueEditor != null)
issueEditor.Cleanup();
this.issueEditorContentControl.Content = null;
// cleanup itself
Messenger.Default.Unregister(this);
// set DataContext to null and call ReleaseExport()
this.DataContext = null;
App.Container.ReleaseExport<ViewModelBase>(_viewModelExport);
_viewModelExport = null;
}
#endregion "ICleanup interface implementation"
}
}
|
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.
Weidong has been an information system professional since 1990. He has a Master's degree in Computer Science, and is currently a MCSD .NET