Skip to content

Commit

Permalink
Added support for Caliburn Convetion Bindings during DesignTime
Browse files Browse the repository at this point in the history
  • Loading branch information
kevicency committed Jan 24, 2012
1 parent e38df68 commit df08108
Show file tree
Hide file tree
Showing 13 changed files with 13,014 additions and 0 deletions.
28 changes: 28 additions & 0 deletions CMContrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "spec", "spec", "{8736DFD2-0
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CMContrib.Spec", "spec\CMContrib.Spec\CMContrib.Spec.csproj", "{C809D8FF-B507-4221-9012-205C608D501D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DesignTimeProperties", "DesignTimeProperties", "{2A643F65-E820-4464-9A9C-347ACA8D6896}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignTimeProperties.WPF", "src\DesignTimeProperties\DesignTimeProperties.WPF\DesignTimeProperties.WPF.csproj", "{982FB578-ABA6-4796-ACF2-FB3E87C3E049}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignTimeProperties.Silverlight", "src\DesignTimeProperties\DesignTimeProperties.Silverlight\DesignTimeProperties.Silverlight.csproj", "{55AF99C8-DE96-4AB3-ACA6-040CE6513E99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -95,6 +101,26 @@ Global
{C809D8FF-B507-4221-9012-205C608D501D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{C809D8FF-B507-4221-9012-205C608D501D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C809D8FF-B507-4221-9012-205C608D501D}.Release|x86.ActiveCfg = Release|Any CPU
{982FB578-ABA6-4796-ACF2-FB3E87C3E049}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{982FB578-ABA6-4796-ACF2-FB3E87C3E049}.Debug|Any CPU.Build.0 = Debug|Any CPU
{982FB578-ABA6-4796-ACF2-FB3E87C3E049}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{982FB578-ABA6-4796-ACF2-FB3E87C3E049}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{982FB578-ABA6-4796-ACF2-FB3E87C3E049}.Debug|x86.ActiveCfg = Debug|Any CPU
{982FB578-ABA6-4796-ACF2-FB3E87C3E049}.Release|Any CPU.ActiveCfg = Release|Any CPU
{982FB578-ABA6-4796-ACF2-FB3E87C3E049}.Release|Any CPU.Build.0 = Release|Any CPU
{982FB578-ABA6-4796-ACF2-FB3E87C3E049}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{982FB578-ABA6-4796-ACF2-FB3E87C3E049}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{982FB578-ABA6-4796-ACF2-FB3E87C3E049}.Release|x86.ActiveCfg = Release|Any CPU
{55AF99C8-DE96-4AB3-ACA6-040CE6513E99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{55AF99C8-DE96-4AB3-ACA6-040CE6513E99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{55AF99C8-DE96-4AB3-ACA6-040CE6513E99}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{55AF99C8-DE96-4AB3-ACA6-040CE6513E99}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{55AF99C8-DE96-4AB3-ACA6-040CE6513E99}.Debug|x86.ActiveCfg = Debug|Any CPU
{55AF99C8-DE96-4AB3-ACA6-040CE6513E99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{55AF99C8-DE96-4AB3-ACA6-040CE6513E99}.Release|Any CPU.Build.0 = Release|Any CPU
{55AF99C8-DE96-4AB3-ACA6-040CE6513E99}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{55AF99C8-DE96-4AB3-ACA6-040CE6513E99}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{55AF99C8-DE96-4AB3-ACA6-040CE6513E99}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -104,5 +130,7 @@ Global
{57D4B3AA-5CAE-465A-9847-1184AB0C2D90} = {3F6964C9-8A90-4F72-82B6-5178A1DD9695}
{CEB90F99-CD77-4F7B-A199-8B7133AFAAF4} = {852785C1-85B4-44DD-A81E-0E7ACE7018D1}
{C809D8FF-B507-4221-9012-205C608D501D} = {8736DFD2-0D28-4636-8C61-88E26EF5BA82}
{982FB578-ABA6-4796-ACF2-FB3E87C3E049} = {2A643F65-E820-4464-9A9C-347ACA8D6896}
{55AF99C8-DE96-4AB3-ACA6-040CE6513E99} = {2A643F65-E820-4464-9A9C-347ACA8D6896}
EndGlobalSection
EndGlobal
11 changes: 11 additions & 0 deletions src/CMContrib.WPF/CMContrib.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@
<Link>Threading\ResultSynchronizationContext.cs</Link>
</Compile>
<Compile Include="ConsoleLog.cs" />
<Compile Include="DesignTime\DesignTime.cs" />
<Compile Include="DesignTime\Helper.cs" />
<Compile Include="DialogCloser.cs" />
<Compile Include="Results\BrowseFolderResult.cs" />
<Compile Include="Helper\FileFilterCollection.cs" />
Expand All @@ -234,6 +236,15 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DesignTimeProperties\DesignTimeProperties.WPF\DesignTimeProperties.WPF.csproj">
<Project>{982FB578-ABA6-4796-ACF2-FB3E87C3E049}</Project>
<Name>DesignTimeProperties.WPF</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
64 changes: 64 additions & 0 deletions src/CMContrib.WPF/DesignTime/DesignTime.cs
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);
}
}
}
10 changes: 10 additions & 0 deletions src/CMContrib.WPF/DesignTime/Helper.cs
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);
}
}
Loading

0 comments on commit df08108

Please sign in to comment.