forked from MvvmCross/MvvmCross
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding BindingEx projects - first steps towards MvvmCross#283
- Loading branch information
Showing
15 changed files
with
862 additions
and
3 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...irrious.MvvmCross.BindingEx.WindowsPhone/Cirrious.MvvmCross.BindingEx.WindowsPhone.csproj
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,88 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>10.0.20506</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{7F3E7612-59B6-4E5B-B300-755DA6647F22}</ProjectGuid> | ||
<ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Cirrious.MvvmCross.BindingEx.WindowsPhone</RootNamespace> | ||
<AssemblyName>Cirrious.MvvmCross.BindingEx.WindowsPhone</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion> | ||
<TargetFrameworkProfile>WindowsPhone71</TargetFrameworkProfile> | ||
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier> | ||
<SilverlightApplication>false</SilverlightApplication> | ||
<ValidateXaml>true</ValidateXaml> | ||
<ThrowErrorsInValidation>true</ThrowErrorsInValidation> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>..\..\Bin\Debug\Mvx\WindowsPhone</OutputPath> | ||
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants> | ||
<NoStdLib>true</NoStdLib> | ||
<NoConfig>true</NoConfig> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>..\..\Bin\Release\Mvx\WindowsPhone</OutputPath> | ||
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants> | ||
<NoStdLib>true</NoStdLib> | ||
<NoConfig>true</NoConfig> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System.Windows" /> | ||
<Reference Include="system" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Net" /> | ||
<Reference Include="mscorlib.extensions" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\Cirrious.MvvmCross.BindingEx.WindowsStore\Bi.n.d.cs"> | ||
<Link>Bi.n.d.cs</Link> | ||
</Compile> | ||
<Compile Include="..\Cirrious.MvvmCross.BindingEx.WindowsStore\La.n.g.cs"> | ||
<Link>La.n.g.cs</Link> | ||
</Compile> | ||
<Compile Include="IMvxBindingCreator.cs" /> | ||
<Compile Include="MvxBindingCreator.cs" /> | ||
<Compile Include="MvxImageUrlValueConverter.cs" /> | ||
<Compile Include="MvxPhoneBindingBuilder.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\CrossCore\Cirrious.CrossCore.WindowsPhone\Cirrious.CrossCore.WindowsPhone.csproj"> | ||
<Project>{2CA6800E-2CB5-4F76-BBE3-C4F7D445AF17}</Project> | ||
<Name>Cirrious.CrossCore.WindowsPhone</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\..\CrossCore\Cirrious.CrossCore\Cirrious.CrossCore.csproj"> | ||
<Project>{CFF6F25A-3C3B-44EE-A54C-2ED4AAFF3ADB}</Project> | ||
<Name>Cirrious.CrossCore</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Cirrious.MvvmCross.Binding\Cirrious.MvvmCross.Binding.csproj"> | ||
<Project>{64DCD397-9019-41E8-A928-E5F5C5DF185B}</Project> | ||
<Name>Cirrious.MvvmCross.Binding</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" /> | ||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" /> | ||
<ProjectExtensions /> | ||
<!-- 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. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
22 changes: 22 additions & 0 deletions
22
Cirrious/Cirrious.MvvmCross.BindingEx.WindowsPhone/IMvxBindingCreator.cs
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,22 @@ | ||
// IMvxBindingCreator.cs | ||
// (c) Copyright Cirrious Ltd. http://www.cirrious.com | ||
// MvvmCross is licensed using Microsoft Public License (Ms-PL) | ||
// Contributions and inspirations noted in readme.md and license.txt | ||
// | ||
// Project Lead - Stuart Lodge, @slodge, [email protected] | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows; | ||
using Cirrious.MvvmCross.Binding.Binders; | ||
|
||
namespace Cirrious.MvvmCross.BindingEx.WindowsPhone | ||
{ | ||
public interface IMvxBindingCreator | ||
{ | ||
void CreateBindings( | ||
object sender, | ||
DependencyPropertyChangedEventArgs args, | ||
Func<string, IEnumerable<MvxBindingDescription>> parseBindingDescriptions); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
Cirrious/Cirrious.MvvmCross.BindingEx.WindowsPhone/MvxBindingCreator.cs
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,111 @@ | ||
// MvxBindingCreator.cs | ||
// (c) Copyright Cirrious Ltd. http://www.cirrious.com | ||
// MvvmCross is licensed using Microsoft Public License (Ms-PL) | ||
// Contributions and inspirations noted in readme.md and license.txt | ||
// | ||
// Project Lead - Stuart Lodge, @slodge, [email protected] | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
using Cirrious.CrossCore; | ||
using Cirrious.CrossCore.Converters; | ||
using Cirrious.CrossCore.WindowsPhone.Converters; | ||
using Cirrious.MvvmCross.Binding; | ||
using Cirrious.MvvmCross.Binding.Binders; | ||
|
||
namespace Cirrious.MvvmCross.BindingEx.WindowsPhone | ||
{ | ||
public class MvxBindingCreator : IMvxBindingCreator | ||
{ | ||
public void CreateBindings(object sender, DependencyPropertyChangedEventArgs args, | ||
Func<string, IEnumerable<MvxBindingDescription>> parseBindingDescriptions) | ||
{ | ||
var attachedObject = sender as FrameworkElement; | ||
if (attachedObject == null) | ||
{ | ||
Mvx.Warning("Null attached FrameworkElement seen in Bi.nd binding"); | ||
return; | ||
} | ||
|
||
var text = args.NewValue as string; | ||
if (String.IsNullOrEmpty(text)) | ||
return; | ||
|
||
var bindingDescriptions = parseBindingDescriptions(text); | ||
if (bindingDescriptions == null) | ||
return; | ||
|
||
var actualType = attachedObject.GetType(); | ||
foreach (var bindingDescription in bindingDescriptions) | ||
{ | ||
var dependencyPropertyName = bindingDescription.TargetName + "Property"; | ||
var propertyInfo = FindProperty(actualType, dependencyPropertyName); | ||
if (propertyInfo == null) | ||
{ | ||
continue; | ||
} | ||
|
||
var property = propertyInfo.GetValue(null); | ||
if (property == null) | ||
{ | ||
Mvx.Warning("DependencyProperty not returned {0}", dependencyPropertyName); | ||
continue; | ||
} | ||
|
||
var newBinding = new System.Windows.Data.Binding() | ||
{ | ||
Path = new PropertyPath(bindingDescription.SourcePropertyPath), | ||
Mode = ConvertMode(bindingDescription.Mode), | ||
Converter = GetConverter(bindingDescription.Converter), | ||
ConverterParameter = bindingDescription.ConverterParameter, | ||
FallbackValue = bindingDescription.FallbackValue | ||
}; | ||
|
||
BindingOperations.SetBinding(attachedObject, (DependencyProperty) property, newBinding); | ||
} | ||
} | ||
|
||
private static FieldInfo FindProperty(Type type, string dependencyPropertyName) | ||
{ | ||
var fieldInfo = type.GetField(dependencyPropertyName, BindingFlags.Static | BindingFlags.Public); | ||
return fieldInfo; | ||
} | ||
|
||
private static IValueConverter GetConverter(IMvxValueConverter converter) | ||
{ | ||
if (converter == null) | ||
return null; | ||
|
||
// TODO - consider caching this wrapper - it is a tiny bit wasteful creating a wrapper for each binding | ||
return new MvxNativeValueConverter(converter); | ||
} | ||
|
||
private static BindingMode ConvertMode(MvxBindingMode mode) | ||
{ | ||
switch (mode) | ||
{ | ||
case MvxBindingMode.Default: | ||
return BindingMode.TwoWay; | ||
|
||
case MvxBindingMode.TwoWay: | ||
return BindingMode.TwoWay; | ||
|
||
case MvxBindingMode.OneWay: | ||
return BindingMode.OneWay; | ||
|
||
case MvxBindingMode.OneTime: | ||
return BindingMode.OneTime; | ||
|
||
case MvxBindingMode.OneWayToSource: | ||
Mvx.Warning("WinPhone doesn't support OneWayToSource"); | ||
return BindingMode.TwoWay; | ||
|
||
default: | ||
throw new ArgumentOutOfRangeException("mode"); | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Cirrious/Cirrious.MvvmCross.BindingEx.WindowsPhone/MvxImageUrlValueConverter.cs
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,24 @@ | ||
// MvxImageUrlValueConverter.cs | ||
// (c) Copyright Cirrious Ltd. http://www.cirrious.com | ||
// MvvmCross is licensed using Microsoft Public License (Ms-PL) | ||
// Contributions and inspirations noted in readme.md and license.txt | ||
// | ||
// Project Lead - Stuart Lodge, @slodge, [email protected] | ||
|
||
using System; | ||
using System.Windows.Media.Imaging; | ||
using Cirrious.CrossCore.Converters; | ||
|
||
namespace Cirrious.MvvmCross.BindingEx.WindowsPhone | ||
{ | ||
public class MvxImageUrlValueConverter : MvxValueConverter<string, BitmapImage> | ||
{ | ||
protected override BitmapImage Convert(string value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | ||
{ | ||
if (string.IsNullOrEmpty(value)) | ||
return null; | ||
|
||
return new BitmapImage(new Uri(value, UriKind.RelativeOrAbsolute)); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
Cirrious/Cirrious.MvvmCross.BindingEx.WindowsPhone/MvxPhoneBindingBuilder.cs
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,67 @@ | ||
// MvxPhoneBindingBuilder.cs | ||
// (c) Copyright Cirrious Ltd. http://www.cirrious.com | ||
// MvvmCross is licensed using Microsoft Public License (Ms-PL) | ||
// Contributions and inspirations noted in readme.md and license.txt | ||
// | ||
// Project Lead - Stuart Lodge, @slodge, [email protected] | ||
|
||
using System; | ||
using System.Reflection; | ||
using System.Windows.Media; | ||
using Cirrious.CrossCore; | ||
using Cirrious.CrossCore.Converters; | ||
using Cirrious.MvvmCross.Binding; | ||
using Cirrious.MvvmCross.Binding.Binders; | ||
|
||
namespace Cirrious.MvvmCross.BindingEx.WindowsPhone | ||
{ | ||
public class MvxPhoneBindingBuilder : MvxCoreBindingBuilder | ||
{ | ||
private readonly Action<IMvxValueConverterRegistry> _fillValueConvertersAction; | ||
|
||
public MvxPhoneBindingBuilder(params Assembly[] valueConverterAssemblies) | ||
{ | ||
_fillValueConvertersAction = (registry) => registry.Fill(valueConverterAssemblies); | ||
} | ||
|
||
public MvxPhoneBindingBuilder( | ||
Action<IMvxValueConverterRegistry> fillValueConvertersAction = null) | ||
{ | ||
_fillValueConvertersAction = fillValueConvertersAction; | ||
} | ||
|
||
public override void DoRegistration() | ||
{ | ||
base.DoRegistration(); | ||
InitializeBindingCreator(); | ||
} | ||
|
||
protected override void FillAutoValueConverters(IMvxAutoValueConverters autoValueConverters) | ||
{ | ||
base.FillAutoValueConverters(autoValueConverters); | ||
autoValueConverters.Register(typeof(string), typeof(ImageSource), new MvxImageUrlValueConverter()); | ||
} | ||
|
||
private void InitializeBindingCreator() | ||
{ | ||
var creator = CreateBindingCreator(); | ||
Mvx.RegisterSingleton<IMvxBindingCreator>(creator); | ||
} | ||
|
||
protected virtual MvxBindingCreator CreateBindingCreator() | ||
{ | ||
return new MvxBindingCreator(); | ||
} | ||
|
||
protected override void FillValueConverters(IMvxValueConverterRegistry registry) | ||
{ | ||
base.FillValueConverters(registry); | ||
|
||
registry.Fill(this.GetType().Assembly); | ||
registry.Fill(typeof(Localization.MvxLanguageConverter).Assembly); | ||
|
||
if (_fillValueConvertersAction != null) | ||
_fillValueConvertersAction(registry); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Cirrious/Cirrious.MvvmCross.BindingEx.WindowsPhone/Properties/AssemblyInfo.cs
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,37 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Resources; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Cirrious.MvvmCross.BindingEx.WindowsPhone")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Cirrious.MvvmCross.BindingEx.WindowsPhone")] | ||
[assembly: AssemblyCopyright("Copyright © 2013")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("7f3e7612-59b6-4e5b-b300-755da6647f22")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Revision and Build Numbers | ||
// by using the '*' as shown below: | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] | ||
[assembly: NeutralResourcesLanguageAttribute("en-US")] |
Oops, something went wrong.