Showing posts with label WPF. Show all posts
Showing posts with label WPF. Show all posts

WPF Logical Resources

WPF Logical Resources
A Logical Resource in WPF is a XAML defined object that can be used by WPF elements inside the user interface.
You can declare a logical resource for the entire window and will be usable by all elements on that window, or you can declare it inside the Resources collection of an element, where it will be usable only within that element. You can also declare it for an entire application and it will usable anywhere.

       
              
              
       



       
            	
              	       
                      
            	
       



       
              
              
       


The application resources collection can be found inside the App.xaml file located in your project.

Every resource must have an x:Key property which defines the name of that specific object. It doesn’t have to be unique in the entire application, but it must be unique in the Resource Collection in which it was defined.

A resource in XAML can be accessed by using the {StaticResource name} syntax.


Mnemonic Keys in WPF

Mnemonic keys are keys that when pressed in combination with the ALT key move the focus to the control they are assigned to.

Labels in WPF have a built in support for mnemonic keys.

A mnemonic key can be specified by using the underscore symbol ( _ ) in front of the key you wish to assign. At runtime, you will notice that the key will appear underlined when the ALT key will be pressed.

Here is an example in XAML:



In this example, we have designated to Label1 a TextBox named TextBox1 and when the ALT+S keys will be pressed in combination, the textbox will receive focus.