|
using System;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Controls;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using IssueVision.Common;
namespace IssueVision.Client
{
public partial class Reports : UserControl, ICleanup
{
#region "Private Data Members"
private const double MinimumWidth = 640;
private Lazy<ViewModelBase> _viewModelExport;
#endregion "Private Data Members"
#region "Constructor"
public Reports()
{
InitializeComponent();
// initialize the UserControl Width & Height
Content_Resized(this, null);
// register for GetChartsMessage
AppMessages.GetChartsMessage.Register(this, OnGetChartsMessage);
if (!ViewModelBase.IsInDesignModeStatic)
{
// Use MEF To load the View Model
_viewModelExport = App.Container.GetExport<ViewModelBase>(
ViewModelTypes.BugReportViewModel);
if (_viewModelExport != null) DataContext = _viewModelExport.Value;
}
}
#endregion "Constructor"
#region "Logic to dynamically set UserControl Width and Height"
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Application.Current.Host.Content.Resized += Content_Resized;
}
private void UserControl_Unloaded(object sender, RoutedEventArgs e)
{
Application.Current.Host.Content.Resized -= Content_Resized;
}
private void Content_Resized(object sender, EventArgs e)
{
// stretch the UserControl to the current browser width if wider than MinimumWidth
if (Application.Current.Host.Content.ActualWidth < MinimumWidth)
Width = MinimumWidth;
else
Width = Application.Current.Host.Content.ActualWidth;
// stretch the UserControl to the current brower Height - Title Height(42) - Menu Height(22)
Height = Application.Current.Host.Content.ActualHeight - 42 - 22;
}
#endregion "Logic to dynamically set UserControl Width and Height"
#region "GetChartsMessage"
private void OnGetChartsMessage(NotificationMessageAction<WriteableBitmap> message)
{
if (message != null)
{
// create the bitmap
var wb = new WriteableBitmap((int)grid_Charts.ActualWidth,
(int)grid_Charts.ActualHeight);
// copy the content into the bitmap
wb.Render(grid_Charts, null);
wb.Invalidate();
// send the bitmap back
message.Execute(wb);
}
}
#endregion "GetChartsMessage"
#region "ICleanup interface implementation"
public void Cleanup()
{
// call Cleanup on its ViewModel
((ICleanup)DataContext).Cleanup();
// cleanup itself
Messenger.Default.Unregister(this);
// set DataContext to null and call ReleaseExport()
DataContext = null;
App.Container.ReleaseExport(_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