Page Index Toggle Pages: [1] 2  Send TopicPrint
Very Hot Topic (More than 25 Replies) Unable to load custom themes (Read 16921 times)
Harshvir
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 37
Joined: Aug 26th, 2020
Unable to load custom themes
Aug 26th, 2020 at 10:43pm
Print Post  
Hi,
I am trying to load custom colors for the keyboard, but I am not getting any success.
I provided the Dynamic resources in my application for brushes but they do not seem to be used.
    <SolidColorBrush x:Key="IC_ButtonBackground" Color="#FF333333"/>
    <SolidColorBrush x:Key="IC_ButtonPressedBackground" Color="#FF0076D7"/>
    <SolidColorBrush x:Key="IC_Foreground" Color="#FFF0F0F0"/>
    <SolidColorBrush x:Key="IC_Background" Color="Transparent"/>


Thanks,
Harshvir
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3444
Joined: Oct 19th, 2005
Re: Unable to load custom themes
Reply #1 - Aug 27th, 2020 at 2:24pm
Print Post  
Hi,

The keyboard loads its resource dictionary for current theme explicitly and might be overwriting your values. Try doing the same yourself from window_loaded handler, e.g.

Code
Select All
void Window_Loaded(object sender, RoutedEventArgs e)
{
    ResourceDictionary res = new ResourceDictionary();
    res.Source = new Uri("pack://application:,,,/mytheme.xaml");
    Application.Current.Resources.MergedDictionaries.Add(res);
} 



where mytheme.xaml contains your brushes -

Code
Select All
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <SolidColorBrush x:Key="IC_ButtonBackground" Color="#FF333333"/>
    <SolidColorBrush x:Key="IC_ButtonPressedBackground" Color="#FF0076D7"/>
    <SolidColorBrush x:Key="IC_Foreground" Color="#FFF0F0F0"/>
    <SolidColorBrush x:Key="IC_Background" Color="Transparent"/>

</ResourceDictionary>
 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Harshvir
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 37
Joined: Aug 26th, 2020
Re: Unable to load custom themes
Reply #2 - Aug 27th, 2020 at 5:12pm
Print Post  
Thanks for the reply. I am able to change the colors now.
But I am still not able to change the color of lowercase characters, which seems to be hardcoded to red, as well as color of extended characters. Third characters that show on top right side.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3444
Joined: Oct 19th, 2005
Re: Unable to load custom themes
Reply #3 - Aug 28th, 2020 at 12:42pm
Print Post  
You can only change these through custom key templates at this time. We'll have in mind refactoring them to brush resources for next release.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Harshvir
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 37
Joined: Aug 26th, 2020
Re: Unable to load custom themes
Reply #4 - Aug 28th, 2020 at 5:54pm
Print Post  
Thanks I followed that method, and I am able to change colors for all the keys now.
I have another problem at hand now. I have attached a screenshot of default keyboard layout with keys under consideration highlighted.
I created converters to show color based on state or Caps and Shift Lock.
In terms of shift it works fine, as all the regular keys update to Upper TextBlock, but the Number/Symbol keys pairs, don't work as expected when Caps Lock on ON.
I check for Caps lock ON in Upper Case converter and mark keys are selected, which is causing number portion to show disabled.

Is there a way to differentiate between keys (without checking the text on key, this will not work for multiple language support). I used Keyboard Layout Creator and every key is considered Regular Key, so same layout is working for them.
  

Untitled_012.png ( 38 KB | 294 Downloads )
Untitled_012.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3444
Joined: Oct 19th, 2005
Re: Unable to load custom themes
Reply #5 - Aug 31st, 2020 at 2:18pm
Print Post  
Hi,

Note that caps lock enabled does not change these keys to typing symbols on physical keyboards, so we keep it like that in the virtual keyboard too. If you need caps to switch to symbols, you might need to create a custom key-derived class. Or do you only need to know if caps lock would have effect on the key for your color converter?

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Harshvir
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 37
Joined: Aug 26th, 2020
Re: Unable to load custom themes
Reply #6 - Aug 31st, 2020 at 3:46pm
Print Post  
I think I did not explain properly.
Here is how I added converter to the resources defined for keys.

Code
Select All
<TextBlock Text="{Binding UpperCase}" Foreground="{Binding UpperCase, Converter={StaticResource UpperCaseColorConverter}}"/>
 



I can easily find if Caps lock is on or not using MindFusion.UI.Wpf.VirtualKeyboard.CapsLocked in my ColorCoverter class.

But the problem is when Caps lock is pressed, for me to update UI whether to highlight the Text or not is tricky as its showing the Upper Textbox Key as highlighted.
I can get around that by checking the character at place to see if that is supposed to be upper case or not for en-US culture key.
But we support multiple languages in our application and hence we use different keyboard, and adding a check for each key will be hard for all the languages.
So I was wondering if there is a way to treat these keys differently rather than Regular Key as currently defined by Virtual Keyboard creator.

Thanks.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3444
Joined: Oct 19th, 2005
Re: Unable to load custom themes
Reply #7 - Sep 1st, 2020 at 12:36pm
Print Post  
Caps lock seems to affect only Latin, Greek and Cyrillic letters, so I guess you could check for them using regex named blocks -

https://docs.microsoft.com/en-us/dotnet/standard/base-types/character-classes-in...
https://stackoverflow.com/questions/11414452/is-there-a-way-to-check-if-text-is-...

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Harshvir
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 37
Joined: Aug 26th, 2020
Re: Unable to load custom themes
Reply #8 - Sep 3rd, 2020 at 1:41am
Print Post  
Hi, Thanks for the response, but that answer did not help me, I try to check the keys in covert function, and all the keys get matched to IsBasicLatin. I tried using the following instead of IsBasicLatin as well, but everything is getting counted as Latin. including the symbols.
Code
Select All
        private bool IsSpecialCharacter(string data)
        {
            if (Regex.IsMatch(data, @"\p{IsCyrillic}"))
            {
                System.Diagnostics.Debug.WriteLine("Keyboard IsCyrillic: data('{0}')", data);
                return true;
            }
            else if (Regex.IsMatch(data, @"\p{IsGreek}"))
            {
                System.Diagnostics.Debug.WriteLine("Keyboard IsGreek: data('{0}')", data);
                return true;
            }
            else if (Regex.IsMatch(data, @"[\u0000-\u024F]+", RegexOptions.None))
            {
                System.Diagnostics.Debug.WriteLine("Keyboard IsBasicLatin: data('{0}')", data);
                return true;
            }
            return false;
        }
 


  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3444
Joined: Oct 19th, 2005
Re: Unable to load custom themes
Reply #9 - Sep 3rd, 2020 at 8:51am
Print Post  
The basic latin block seem to also include punctuation, digits and control codes -
https://en.wikipedia.org/wiki/Basic_Latin_(Unicode_block)

So add explicit char.IsLetter(c) check before comparing against it -

Code
Select All
char c = '!';
Debug.WriteLine(char.IsLetter(c) && Regex.IsMatch(c.ToString(), @"\p{IsBasicLatin}"));
//false
 



The keyboard relies on the OS to handle modifier keys and there's nothing built into it to determine how Caps affects the keys; regex blocks are best way we can think of.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3444
Joined: Oct 19th, 2005
Re: Unable to load custom themes
Reply #10 - Sep 3rd, 2020 at 8:57am
Print Post  
Greek block includes some punctuation too, while Cyrillic does not -
https://en.wikipedia.org/wiki/Greek_and_Coptic
https://en.wikipedia.org/wiki/Cyrillic_(Unicode_block)

so add IsLetter check for Greek as well.
  
Back to top
 
IP Logged
 
Harshvir
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 37
Joined: Aug 26th, 2020
Re: Unable to load custom themes
Reply #11 - Sep 3rd, 2020 at 1:40pm
Print Post  
Thanks. It worked for the quick test with english. I will run tests with other language that we support and will verify if everything is working as expected.

Thanks again for your support.
  
Back to top
 
IP Logged
 
Harshvir
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 37
Joined: Aug 26th, 2020
Re: Unable to load custom themes
Reply #12 - Sep 4th, 2020 at 2:27am
Print Post  
My issue is still going on for non-english language.
Thanks for all the help. I will try to find character classes needed and should be able to resolve the issues.

Thanks.
  
Back to top
 
IP Logged
 
Harshvir
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 37
Joined: Aug 26th, 2020
Re: Unable to load custom themes
Reply #13 - Sep 9th, 2020 at 6:20pm
Print Post  
I have a small suggestion for Future release, it will make UI very intuitive.
Rather than showing 3 characters at the same time.
Show the character which is currently being sent out for the key.
Like we have three textblocks Upper, Alter and Lower.
If shift is ON, then we will be sending Upper block keys, then in that case Keyboard should show only Upper case key.

I am still not able to get all the key highlighting working correctly. for a combination of Caps and Shift. Fixing for 1 language, breaks for other.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3444
Joined: Oct 19th, 2005
Re: Unable to load custom themes
Reply #14 - Sep 14th, 2020 at 7:16am
Print Post  
Actually the keyboard does query the OS for character labels when CapsLock is on, and that's exposed as CapitalCase property of RegularKey, so you might try using that in your converters. There's an additional CurrentCase property that's set according to shift/caps states, you could use that to show a single character as in https://mindfusion.eu/Forum/YaBB.pl?num=1478183033/1#1

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint