The MindFusion Forums
Virtual Keyboard Components >> WPF >> Can I set the template and style in xaml instead of code behind
https://mindfusion.eu/Forum/YaBB.pl?num=1482174360

Message started by Dan Neely on Dec 19th, 2016 at 7:06pm

Title: Can I set the template and style in xaml instead of code behind
Post by Dan Neely on Dec 19th, 2016 at 7:06pm
Your example code all shows these being set in code behind; which means that the UI designer always shows your default layout instead of the layout I'm using.

ex from StyleSamples.cs in your example projects:


Code (c++):
virtualKeyboard.TemplateLayout = KeyboardLayout.Create(
                    this.GetType().Assembly.GetManifestResourceStream("Styles.CustomLayout.xml"));
//set custom style of VirtualKeyboardStyle from file
resources.Source = new Uri("/Styles;component/VirtualKeyboardWithImages.xaml", UriKind.Relative);
this.Resources.MergedDictionaries.Add(resources);



Title: Re: Can I set the template and style in xaml instead of code behind
Post by Slavcho on Dec 20th, 2016 at 4:08pm
You can define keyboard layout from Xaml like this -
[code]
<vk:VirtualKeyboard>
     <vk:VirtualKeyboard.TemplateLayout>
           <vk:KeyboardLayout>
                 <vk:KeyboardLayout.Keys>
                       <vk:RegularKey Content="A" Left="10" Top="10" Width="60" Height="60" />
                       <vk:RegularKey Content="B" Left="80" Top="10" Width="60" Height="60" />
                       ...
                 </vk:KeyboardLayout.Keys>
           </vk:KeyboardLayout>
     </vk:VirtualKeyboard.TemplateLayout>
</vk:VirtualKeyboard>[/code]

Seeing an external layout file created using the Keyboard Creator tool in VS design time should be possible too - try creating an IValueConverter that returns KeyboardLayout.Create(filename) from Convert method and use it in TemplateLayout binding expression.

Regards,
Slavcho

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.