[C] added intellisense for Keyboard property (#7553) fixes azdo 835646
authorPavel Yakovlev <v-payako@microsoft.com>
Tue, 17 Sep 2019 22:35:37 +0000 (01:35 +0300)
committerRui Marinho <me@ruimarinho.net>
Tue, 17 Sep 2019 22:35:37 +0000 (23:35 +0100)
Xamarin.Forms.Core.Design/AttributeTableBuilder.cs
Xamarin.Forms.Core.Design/KeyboardDesignTypeConverter.cs [new file with mode: 0644]
Xamarin.Forms.Core.Design/Xamarin.Forms.Core.Design.csproj

index f98b86e759828128c1decfc15842e01a99f69cd7..e6cefb86a1e7c1d7a6d65c06cd4a3c18ca2c421c 100644 (file)
@@ -43,6 +43,14 @@ namespace Xamarin.Forms.Core.Design
                                "ItemsLayout",
                           new System.ComponentModel.TypeConverterAttribute(typeof(ItemsLayoutDesignTypeConverter))));
 
+                       AddCallback(typeof(InputView), builder => builder.AddCustomAttributes(
+                          nameof(Keyboard),
+                          new System.ComponentModel.TypeConverterAttribute(typeof(KeyboardDesignTypeConverter))));
+
+                       AddCallback(typeof(EntryCell), builder => builder.AddCustomAttributes(
+                          nameof(Keyboard),
+                          new System.ComponentModel.TypeConverterAttribute(typeof(KeyboardDesignTypeConverter))));
+
                        // 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.
diff --git a/Xamarin.Forms.Core.Design/KeyboardDesignTypeConverter.cs b/Xamarin.Forms.Core.Design/KeyboardDesignTypeConverter.cs
new file mode 100644 (file)
index 0000000..aed4c92
--- /dev/null
@@ -0,0 +1,55 @@
+namespace Xamarin.Forms.Core.Design
+{
+       using System.Linq;
+       using System.ComponentModel;
+       using System;
+       using System.Reflection;
+
+       public class KeyboardDesignTypeConverter : TypeConverter
+       {
+               public KeyboardDesignTypeConverter()
+               {
+               }
+
+               protected StandardValuesCollection Values
+               {
+                       get;
+                       set;
+               }
+
+               public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
+               {
+                       // This tells XAML this converter can be used to process strings
+                       // Without this the values won't show up as hints
+                       if (sourceType == typeof(string))
+                               return true;
+
+                       return base.CanConvertFrom(context, sourceType);
+               }
+
+               public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
+               {
+                       if (Values == null)
+                       {
+                               var props = typeof(Keyboard)
+                                       .GetProperties(BindingFlags.Static | BindingFlags.Public)
+                                       .Where(p => p.CanRead)
+                                       .Select(p => p.Name)
+                                       .ToArray();
+                               Values = new StandardValuesCollection(props);
+                       }
+
+                       return Values;
+               }
+
+               public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
+               {
+                       return false;
+               }
+
+               public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
+               {
+                       return true;
+               }
+       }
+}
\ No newline at end of file
index 18e9fe52b5ba916f658b69cccc5c0259bf8b53c0..ba1e5c410574f14ada1fd155ab415457899297dc 100644 (file)
@@ -73,6 +73,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="ItemsLayoutDesignTypeConverter.cs" />
+    <Compile Include="KeyboardDesignTypeConverter.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- Ensure that all images in the 'mac' and 'win' subdirectories are included as embedded resources -->