dirty-denver
Thursday, November 24, 2011
Monster Drilldown
i.e. whole process ->
start middle end ->
start_start start_middle start_end, middle_start middle_middle middle_end, end_start end_middle end_end
http://www.ex-tempore.org/little/little.htm
Friday, November 11, 2011
Some TFS Links
Tuesday, June 15, 2010
MvvmFoundation Extension – ValidationViewModelBase
Does some validation of the properties and has some structures to display the errors
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace MvvmFoundation.Wpf
{
/// <summary>
/// ViewModelBase with Validation via IDataErrorInfo.
/// </summary>
public abstract class ValidationViewModelBase : ObservableObject, IDataErrorInfo
{
#region IDataErrorInfo Code
/// <summary>
/// Implement this in the Implementing Class. Throw an exception to allow validation to show on the UI.
/// </summary>
/// <param name="propertyName">The Property to Validate</param>
public abstract string this[string propertyName] { get; }
/// <summary>
/// IDataErrorInfo.Error
/// </summary>
public string Error
{
get
{
if (HasValidationErrors)
return "Invalid";
else
return "";
}
}
/// <summary>
/// Add an Error
/// </summary>
/// <param name="key">The key of the Error</param>
/// <param name="value">The Value/Reason of the Error</param>
public void AddError(string key, string value)
{
RemoveError(key);
errorMessages.Add(key, value);
RaisePropertyChanged("ValidationErrors");
RaisePropertyChanged("HasValidationErrors");
}
/// <summary>
/// Remove an Error by key
/// </summary>
/// <param name="key">the error key to remove</param>
public void RemoveError(string key)
{
if (errorMessages.ContainsKey(key))
errorMessages.Remove(key);
RaisePropertyChanged("ValidationErrors");
RaisePropertyChanged("HasValidationErrors");
}
/// <summary>
/// String Representation of the Validation Errors
/// </summary>
public string ValidationErrors { get { return getErrorString(); } }
/// <summary>
/// Has Validation errors ?
/// </summary>
public bool HasValidationErrors { get { return errorMessages.Count > 0; } }
#region Implementation Details
private IDictionary<string, string> errorMessages = new Dictionary<string, string>();
private string getErrorString()
{
StringBuilder value = new StringBuilder();
foreach (KeyValuePair<string, string> item in errorMessages)
value.AppendLine(string.Format("{0} - {1}", item.Key, item.Value));
return value.ToString();
}
#endregion
#endregion
}
}
MVVM, ViewModel-DataContext and WPF
There seems to be a view taken by people,strategies-of-binding, that data binding from the View to the ViewModel should be done in a standard way and NO OTHER WAY.
This seems silly to me, as there are some many different ways to do it, and many more contexts when you need to use a different approach.
I preferred using UserControls for my views. The binding method I commonly use is to use the XAML <UserControl.DataContext>, NOT THE CODE BEHIND FILE
i.e.
<UserControl x:Class=”SomeNamespace.View.AControl” xmlns:ViewModel="clr-namespace:ANamespace.ViewModel"... >
<UserControl.DataContext><vm:AControlViewModel/></UserControl.DataContext>
</UserControl>
But in some cases this is limited. For Example, I want a ViewModeled UserControl “UC_B” within another ViewModeled UserControl “UC_A” and have “UC_A”s ViewModel use “UC_B”s ViewModel Properties
i.e. A Reusable DICOM Connection Parameters UserControl<UserControl>
<UserControl.DataContext><vm:UC_SearchStudyControlViewModel/></UserControl.DataContext> <View:DicomConnectionParametersControl x:Name="SearchConnectionParameters" DataContext="{Binding Path=UC_ConnectionParametersViewModel}" DockPanel.Dock="Top" /> ...
</UserControl>
So now I’m still binding via the DataContext of the View to the View’s ViewModel, but in a different way i.e. the ViewModel is a Property of another ViewModel. This could not be done with the previous example, the Views ViewModel is within a different Views ViewModel.
i.e. B.DataContext = A.DataContext.Bs_ViewModelNote there are other ways to pass data between ViewModel,i.e. Messenger , and there are some drawbacks, Binding to Large CLR Objects, in this implementation if you have a large ViewModel. The Dependencies between the ViewModels is also increased by this, i.e. if Bs_ViewModel changes A might need refactoring, but the simplicity of this solution, compared implementing a Messenger, outweighs the minor dependency increase.
Image Render Transformations
Image binding to Viewmodel :
- ImageData (bitmap data)
- ZOOM (zooming)
- TX / TY (translation)
<Image Stretch="None" Source="{Binding Path=ImageData, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" >
<Image.LayoutTransform>
<ScaleTransform ScaleX="{Binding Path=ZOOM}" ScaleY="{Binding Path=ZOOM}" />
</Image.LayoutTransform>
<Image.RenderTransform>
<TransformGroup>
<TranslateTransform X="{Binding Path=TX}" Y="{Binding Path=TY}"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
WPF - Multiple Display
The Method
Use the System.Windows.Forms.Screen API to setup the displays.
The PrimaryScreen Property is the primary display, Other Displays are given by the AllScreens Property (System.Windows.Forms.Screen[])
Example with three windows (ImageViewer Application)
1)Take the StartUri element out of App.xaml and add the Startup event
<Application x:Class="DicomImageViewer.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"
Startup="Application_Startup">
<Application.Resources>
</Application.Resources>
</Application>
2)Add the Startup event handler
private void Application_Startup(object sender, StartupEventArgs e)
{
setDisplayRects(MainDisplayWindow, ImageBox1, ImageBox2);
}
2)This is an example of the ImageViewer for triple display
(note if 1 or 2 displays it subdivides the displays)
public void setDisplayRects(MainWindow main, ImageWindow img1, ImageWindow img2)
{
System.Windows.Forms.Screen s0;
System.Windows.Forms.Screen s1;
System.Windows.Forms.Screen s2;
switch (System.Windows.Forms.Screen.AllScreens.Count())
{
case 3:
s0 = System.Windows.Forms.Screen.PrimaryScreen;
main.Top = s0.WorkingArea.Top;
main.Left = s0.WorkingArea.Left;
main.WindowState = WindowState.Maximized;
main.Show();
s1 = System.Windows.Forms.Screen.AllScreens[1];
img1.Top = s1.WorkingArea.Top;
img1.Left = s1.WorkingArea.Left;
img1.WindowState = WindowState.Maximized;
img1.Show();
img1.Owner = main;
s2 = System.Windows.Forms.Screen.AllScreens[2];
img2.Top = s2.WorkingArea.Top;
img2.Left = s2.WorkingArea.Left;
img2.WindowState = WindowState.Maximized;
img2.Show();
img2.Owner = main;
break;
case 2:
s0 = System.Windows.Forms.Screen.PrimaryScreen;
main.Top = s0.WorkingArea.Top;
main.Left = s0.WorkingArea.Left;
main.Show();
s1 = System.Windows.Forms.Screen.AllScreens[1];
img1.Top = s1.WorkingArea.Top;
img1.Left = s1.WorkingArea.Left;
img1.Width = s1.WorkingArea.Width;
img1.Height = s1.WorkingArea.Height / 2;
img1.Show();
img1.Owner = main;
img2.Top = s1.WorkingArea.Top + s1.WorkingArea.Height / 2;
img2.Left = s1.WorkingArea.Left;
img2.Width = s1.WorkingArea.Width;
img2.Height = s1.WorkingArea.Height / 2;
img2.Show();
img2.Owner = main;
break;
case 1:
s0 = System.Windows.Forms.Screen.PrimaryScreen;
main.Top = s0.WorkingArea.Top;
main.Left = s0.WorkingArea.Left;
main.Width = s0.WorkingArea.Width;
main.Height = s0.WorkingArea.Height / 3;
main.Show();
img1.Top = s0.WorkingArea.Top + s0.WorkingArea.Height / 3;
img1.Left = s0.WorkingArea.Left;
img1.Width = s0.WorkingArea.Width;
img1.Height = s0.WorkingArea.Height / 3;
img1.Show();
img1.Owner = main;
img2.Top = s0.WorkingArea.Top + (2 * s0.WorkingArea.Height / 3);
img2.Left = s0.WorkingArea.Left;
img2.Width = s0.WorkingArea.Width;
img2.Height = s0.WorkingArea.Height / 3;
img2.Show();
img2.Owner = main;
break;
}
}
Wednesday, June 9, 2010
Some Medical Display Specs
http://news.soft32.com/nvidia-and-planar-to-fight-breast-cancer_5645.html
//16MP: 3200 x 5120(WHXGA), 10-bit gray - (30.0') - 200 dpi
//[16384000] pixels (16/10 1.6 ratio)
*NOTE: Strikethrough denotes assumed values
//http://www.ndssi.com/products/dome/ex-grayscale/index.php
//5MP: 2048 x 2560(QSXGA), 8-bit gray - (21.3') - 154 dpi
//5242880 pixels (5/4 1.25 ratio)
//3MP: 1536 x 2048(QXGA), 8-bit and 24-bit per pixel - (20.8') - 123 dpi
//3145728 pixels (4/3 1.33 ratio)
//2MP: 1200 x 1600(UXGA), 8-bit and 24-bit per pixel - (19.6') - 102 dpi
//1920000 pixels (5/4 1.25 ratio)
http://en.wikipedia.org/wiki/File:Vector_Video_Standards2.svg