diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 13:02:25 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 16:13:41 -0700 |
commit | 17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch) | |
tree | b5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Core.Design | |
download | xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2 xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip |
Initial import
Diffstat (limited to 'Xamarin.Forms.Core.Design')
-rw-r--r-- | Xamarin.Forms.Core.Design/AttributeTableBuilder.cs | 74 | ||||
-rw-r--r-- | Xamarin.Forms.Core.Design/EnumConverter.cs | 14 | ||||
-rw-r--r-- | Xamarin.Forms.Core.Design/Properties/AssemblyInfo.cs | 7 | ||||
-rw-r--r-- | Xamarin.Forms.Core.Design/RegisterMetadata.cs | 9 | ||||
-rw-r--r-- | Xamarin.Forms.Core.Design/Xamarin.Forms.Core.Design.csproj | 76 | ||||
-rw-r--r-- | Xamarin.Forms.Core.Design/packages.config | 4 |
6 files changed, 184 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core.Design/AttributeTableBuilder.cs b/Xamarin.Forms.Core.Design/AttributeTableBuilder.cs new file mode 100644 index 00000000..07571d4c --- /dev/null +++ b/Xamarin.Forms.Core.Design/AttributeTableBuilder.cs @@ -0,0 +1,74 @@ +using System; +using System.ComponentModel; +using System.Linq; +using System.Windows.Markup; +using Microsoft.Windows.Design; + +namespace Xamarin.Forms.Core.Design +{ + internal class AttributeTableBuilder : Microsoft.Windows.Design.Metadata.AttributeTableBuilder + { + public AttributeTableBuilder () + { + // Turn off validation of values, which doesn't work for OnPlatform/OnIdiom + AddCustomAttributes (typeof (AbsoluteLayout).Assembly, + new XmlnsSupportsValidationAttribute ("http://xamarin.com/schemas/2014/forms", false)); + + // Style isn't a view, make it visible + AddCallback (typeof(Style), builder => builder.AddCustomAttributes( + new EditorBrowsableAttribute (EditorBrowsableState.Always), + new System.Windows.Markup.ContentPropertyAttribute("Setters"), + // Since the class doesn't have a public parameterless ctor, we need to provide a converter + new System.ComponentModel.TypeConverterAttribute(typeof(StringConverter)))); + + // The Setter.Value can actually come from an <OnPlatform />, so enable it as Content. + AddCallback (typeof (Setter), builder => builder.AddCustomAttributes ( + new EditorBrowsableAttribute (EditorBrowsableState.Always), + new System.Windows.Markup.ContentPropertyAttribute("Value"))); + + // Special case for FontSize which isn't an enum. + var fontElements = typeof(View).Assembly.ExportedTypes.Where(t => typeof(IFontElement).IsAssignableFrom(t)); + foreach (var fontElement in fontElements) { + AddCallback (fontElement, builder => builder.AddCustomAttributes ( + "FontSize", + new System.ComponentModel.TypeConverterAttribute (typeof (EnumConverter<NamedSize>)))); + } + + // TODO: OnPlatform/OnIdiom + // These two should be proper markup extensions, to follow WPF syntax for those. + // That would allow us to turn on XAML validation, which otherwise fails. + // NOTE: the two also need to provide a non-generic, object-based T so that + // the language service can find the type by its name. That class can be internal + // though, since its visibility in the markup is controlled by the EditorBrowsableAttribute. + // Make OnPlatform/OnIdiom visible for intellisense, and set as markup extension. + AddCallback (typeof (OnPlatform<>), builder => builder.AddCustomAttributes (new Attribute[] { + new EditorBrowsableAttribute (EditorBrowsableState.Always), + //new System.ComponentModel.TypeConverterAttribute(typeof(AnythingConverter)), + //new System.Windows.Markup.MarkupExtensionReturnTypeAttribute (), + })); + AddCallback (typeof (OnIdiom<>), builder => builder.AddCustomAttributes (new Attribute[] { + new EditorBrowsableAttribute (EditorBrowsableState.Always), + //new System.ComponentModel.TypeConverterAttribute(typeof(AnythingConverter)), + //new System.Windows.Markup.MarkupExtensionReturnTypeAttribute (), + })); + } + } + + internal class AnythingConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType) + { + return true; + } + + public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType) + { + return true; + } + + public override bool IsValid (ITypeDescriptorContext context, object value) + { + return true; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Core.Design/EnumConverter.cs b/Xamarin.Forms.Core.Design/EnumConverter.cs new file mode 100644 index 00000000..21deabcd --- /dev/null +++ b/Xamarin.Forms.Core.Design/EnumConverter.cs @@ -0,0 +1,14 @@ +using System.ComponentModel; + +namespace Xamarin.Forms.Core.Design +{ + /// <summary> + /// Generic version of the <see cref="EnumConverter"/> for reuse. + /// </summary> + internal class EnumConverter<T> : EnumConverter + { + public EnumConverter () : base(typeof(T)) + { + } + } +} diff --git a/Xamarin.Forms.Core.Design/Properties/AssemblyInfo.cs b/Xamarin.Forms.Core.Design/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..1c6cce84 --- /dev/null +++ b/Xamarin.Forms.Core.Design/Properties/AssemblyInfo.cs @@ -0,0 +1,7 @@ +using System.Reflection; +using Microsoft.Windows.Design.Metadata; + +[assembly: AssemblyTitle ("Xamarin.Forms.Core.Design")] +[assembly: AssemblyDescription ("Provides the design-time metadata for the XAML language service.")] + +[assembly: ProvideMetadata (typeof (Xamarin.Forms.Core.Design.RegisterMetadata))]
\ No newline at end of file diff --git a/Xamarin.Forms.Core.Design/RegisterMetadata.cs b/Xamarin.Forms.Core.Design/RegisterMetadata.cs new file mode 100644 index 00000000..59a2a095 --- /dev/null +++ b/Xamarin.Forms.Core.Design/RegisterMetadata.cs @@ -0,0 +1,9 @@ +using Microsoft.Windows.Design.Metadata; + +namespace Xamarin.Forms.Core.Design +{ + internal class RegisterMetadata : IProvideAttributeTable + { + public AttributeTable AttributeTable { get { return new AttributeTableBuilder ().CreateTable (); } } + } +} diff --git a/Xamarin.Forms.Core.Design/Xamarin.Forms.Core.Design.csproj b/Xamarin.Forms.Core.Design/Xamarin.Forms.Core.Design.csproj new file mode 100644 index 00000000..7b02ea45 --- /dev/null +++ b/Xamarin.Forms.Core.Design/Xamarin.Forms.Core.Design.csproj @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{98637471-8E5C-4DDE-89CA-2EAA664FB0EF}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Xamarin.Forms.Core.Design</RootNamespace> + <AssemblyName>Xamarin.Forms.Core.Design</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <NuGetPackageImportStamp> + </NuGetPackageImportStamp> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup Condition=" '$(OS)' != 'Unix' "> + <Reference Include="Microsoft.Windows.Design.Extensibility, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\lib\Microsoft.Windows.Design.Extensibility.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Xaml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="..\Xamarin.Forms.Core\Properties\GlobalAssemblyInfo.cs"> + <Link>Properties\GlobalAssemblyInfo.cs</Link> + </Compile> + </ItemGroup> + <ItemGroup Condition=" '$(OS)' != 'Unix' "> + <Compile Include="AttributeTableBuilder.cs" /> + <Compile Include="EnumConverter.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="RegisterMetadata.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj"> + <Project>{57b8b73d-c3b5-4c42-869e-7b2f17d354ac}</Project> + <Name>Xamarin.Forms.Core</Name> + <GenerateDesignMetadata>true</GenerateDesignMetadata> + <Private>False</Private> + </ProjectReference> + </ItemGroup> + <ItemGroup Condition=" '$(OS)' != 'Unix' "> + <None Include="packages.config" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets') And '$(OS)' != 'Unix' " /> + <Import Project="..\packages\Xamarin.Forms.Design.1.0.14-pre\build\Xamarin.Forms.Design.targets" Condition="Exists('..\packages\Xamarin.Forms.Design.1.0.14-pre\build\Xamarin.Forms.Design.targets') And '$(OS)' != 'Unix'" /> + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild" Condition=" '$(OS)' != 'Unix' "> + <PropertyGroup> + <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> + </PropertyGroup> + <Error Condition="!Exists('..\packages\Xamarin.Forms.Design.1.0.14-pre\build\Xamarin.Forms.Design.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Forms.Design.1.0.14-pre\build\Xamarin.Forms.Design.targets'))" /> + </Target> +</Project>
\ No newline at end of file diff --git a/Xamarin.Forms.Core.Design/packages.config b/Xamarin.Forms.Core.Design/packages.config new file mode 100644 index 00000000..6e99fb80 --- /dev/null +++ b/Xamarin.Forms.Core.Design/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Xamarin.Forms.Design" version="1.0.14-pre" targetFramework="net45" /> +</packages>
\ No newline at end of file |