mirror of https://github.com/AMT-Cheif/Stylet.git
Merge branch 'release/1.1.6'
This commit is contained in:
commit
40a598c132
|
@ -1,6 +1,12 @@
|
|||
Stylet Changelog
|
||||
================
|
||||
|
||||
v1.1.6
|
||||
------
|
||||
|
||||
- s:Action supports a wider range of events (including KeyDown)
|
||||
- Display a clearer message if the user tries to display a Window using s:View.Model
|
||||
|
||||
v1.1.5
|
||||
------
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Stylet</id>
|
||||
<version>1.1.5</version>
|
||||
<version>1.1.6</version>
|
||||
<title>Stylet</title>
|
||||
<authors>Antony Male</authors>
|
||||
<owners>Antony Male</owners>
|
||||
|
|
|
@ -35,5 +35,5 @@ using System.Windows.Markup;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.5.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.5.0")]
|
||||
[assembly: AssemblyVersion("1.1.6.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.6.0")]
|
||||
|
|
|
@ -105,6 +105,13 @@ namespace Stylet
|
|||
{
|
||||
logger.Info("View.Model changed for {0} from {1} to {2}", targetLocation, oldValue, newValue);
|
||||
var view = this.CreateAndBindViewForModelIfNecessary(newValue);
|
||||
if (view is Window)
|
||||
{
|
||||
var e = new StyletInvalidViewTypeException(String.Format("s:View.Model=\"...\" tried to show a View of type '{0}', but that View derives from the Window class. " +
|
||||
"Make sure any Views you display using s:View.Model=\"...\" do not derive from Window (use UserControl or similar)", view.GetType().Name));
|
||||
logger.Error(e);
|
||||
throw e;
|
||||
}
|
||||
View.SetContentProperty(targetLocation, view);
|
||||
}
|
||||
else
|
||||
|
@ -273,4 +280,19 @@ namespace Stylet
|
|||
this.ViewTypeName = viewTypeName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exception raise when the located View is of the wrong type (Window when expected UserControl, etc)
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2237:MarkISerializableTypesWithSerializable")]
|
||||
public class StyletInvalidViewTypeException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialises a new instance of the <see cref="StyletInvalidViewException"/> class
|
||||
/// </summary>
|
||||
/// <param name="message">Message associated with the Exception</param>
|
||||
public StyletInvalidViewTypeException(string message)
|
||||
: base(message)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,8 +124,9 @@ namespace Stylet
|
|||
var window = view as Window;
|
||||
if (window == null)
|
||||
{
|
||||
var e = new ArgumentException(String.Format("WindowManager.ShowWindow or .ShowDialog tried to show a View of type '{0}', but that View doesn't derive from the Window class. " +
|
||||
"Make sure any Views you display derive from Window (not UserControl, etc)", view == null ? "(null)" : view.GetType().Name));
|
||||
var e = new StyletInvalidViewTypeException(String.Format("WindowManager.ShowWindow or .ShowDialog tried to show a View of type '{0}', but that View doesn't derive from the Window class. " +
|
||||
"Make sure any Views you display using WindowManager.ShowWindow or .ShowDialog derive from Window (not UserControl, etc)",
|
||||
view == null ? "(null)" : view.GetType().Name));
|
||||
logger.Error(e);
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ namespace Stylet.Xaml
|
|||
if (propertyAsMethodInfo != null)
|
||||
{
|
||||
var parameters = propertyAsMethodInfo.GetParameters();
|
||||
if (parameters.Length == 2 && typeof(RoutedEventHandler).IsAssignableFrom(parameters[1].ParameterType))
|
||||
if (parameters.Length == 2 && typeof(Delegate).IsAssignableFrom(parameters[1].ParameterType))
|
||||
{
|
||||
var ec = new EventAction((DependencyObject)valueService.TargetObject, parameters[1].ParameterType, this.Method, this.EventNullTargetBehaviour, this.EventActionNotFoundBehaviour);
|
||||
return ec.GetDelegate();
|
||||
|
|
|
@ -178,6 +178,19 @@ namespace StyletUnitTests
|
|||
Assert.AreEqual(view, target.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnModelChangedThrowsIfViewIsAWindow()
|
||||
{
|
||||
var target = new ContentControl();
|
||||
var model = new object();
|
||||
var view = new Window();
|
||||
var viewManager = new CreatingAndBindingViewManager(this.viewManagerConfig.Object);
|
||||
|
||||
viewManager.View = view;
|
||||
|
||||
Assert.Throws<StyletInvalidViewTypeException>(() => viewManager.OnModelChanged(target, null, model));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateViewForModelReturnsNullIfViewNotFound()
|
||||
{
|
||||
|
|
|
@ -88,7 +88,7 @@ namespace StyletUnitTests
|
|||
{
|
||||
var model = new object();
|
||||
this.viewManager.Setup(x => x.CreateAndBindViewForModelIfNecessary(model)).Returns(new UIElement());
|
||||
Assert.Throws<ArgumentException>(() => this.windowManager.CreateWindow(model, false));
|
||||
Assert.Throws<StyletInvalidViewTypeException>(() => this.windowManager.CreateWindow(model, false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
Loading…
Reference in New Issue