0

I use the keyboard control from here.

The resources are defined in xaml:

   <Grid.Resources>
            <ResourceDictionary x:Name="resdictionary">
                <!-- Img sources-->
                <ImageSource x:Key="EngRus">/TermControls;component/Images/Eng-Rus.png</ImageSource>
                <ImageSource x:Key="gEngRus">/TermControls;component/Images/gEng-Rus.png</ImageSource>
 ...

How can I replace them with images loaded on runtime? I played around with findresources without success.

1
  • You have 2 findresources, application and frameworkelement check which one you are using... Commented Jan 6, 2017 at 18:34

1 Answer 1

1

You can access a resource in a ResourceDictionary by its key:

public OnScreenKeyboard()
{
    this.InitializeComponent();
    System.Windows.Media.ImageSource EngRus = MainGrid.Resources["EngRus"] as System.Windows.Media.ImageSource;
}

...and then replace it with another resource with the same key:

public OnScreenKeyboard()
{
    this.InitializeComponent();
    //remove the old resource
    MainGrid.Resources.Remove("EngRus");

    //create a new BitmapImage
    System.Windows.Media.Imaging.BitmapImage image = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("/TermControls;component/Images/shift.png", System.UriKind.RelativeOrAbsolute));
    MainGrid.Resources.Add("EngRus", image);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.