-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Caliburn Convetion Bindings during DesignTime
- Loading branch information
Showing
13 changed files
with
13,014 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.Windows; | ||
using System.Windows.Data; | ||
|
||
namespace Caliburn.Micro.DesignTimeSupport | ||
{ | ||
public static class DesignTime | ||
{ | ||
public static DependencyProperty EnableProperty = | ||
DependencyProperty.RegisterAttached( | ||
"Enable", | ||
typeof(bool), | ||
typeof(DesignTime), | ||
new PropertyMetadata(new PropertyChangedCallback(EnableChanged))); | ||
|
||
#if !SILVERLIGHT && !WP7 | ||
[AttachedPropertyBrowsableForTypeAttribute(typeof(DependencyObject))] | ||
#endif | ||
public static bool GetEnable(DependencyObject dependencyObject) | ||
{ | ||
return (bool)dependencyObject.GetValue(EnableProperty); | ||
} | ||
|
||
|
||
public static void SetEnable(DependencyObject dependencyObject, bool value) | ||
{ | ||
dependencyObject.SetValue(EnableProperty, value); | ||
} | ||
|
||
static void EnableChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
if (!Execute.InDesignMode) | ||
return; | ||
|
||
BindingOperations.SetBinding(d, DataContextProperty, (bool)e.NewValue ? new Binding() : null); | ||
} | ||
|
||
|
||
private static readonly DependencyProperty DataContextProperty = | ||
DependencyProperty.RegisterAttached( | ||
"DataContext", | ||
typeof(object), | ||
typeof(DesignTime), | ||
new PropertyMetadata(new PropertyChangedCallback(DataContextChanged)) | ||
); | ||
|
||
|
||
|
||
private static void DataContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
if (!Execute.InDesignMode) | ||
return; | ||
|
||
object enable = d.GetValue(EnableProperty); | ||
if (enable == null || ((bool)enable) == false || e.NewValue == null) | ||
return; | ||
|
||
var fe = d as FrameworkElement; | ||
if (fe == null) | ||
return; | ||
|
||
ViewModelBinder.Bind(e.NewValue, d, string.IsNullOrEmpty(fe.Name) ? fe.GetHashCode().ToString() : fe.Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Windows; | ||
|
||
namespace Caliburn.Micro.DesignTimeSupport | ||
{ | ||
public static class Helper | ||
{ | ||
public static Type DependencyObjectType = typeof (DependencyObject); | ||
} | ||
} |
Oops, something went wrong.