Showing posts with label Control Template. Show all posts
Showing posts with label Control Template. Show all posts

WPF How to use Resource Dictionary in XAML



In this article, we will learn how we can use merge a resource dictionary in WPF XAML.


As we all know, that WPF applications supports rich media and graphics support, styles and templates should be managed in such a way that they can be reused. Styles can be defined in the same XAML file or all the styles and templates which are reusable across different screens can be accumulated in a Resource Dictionary File. 


What is Resource Dictionary?


In Resource Dictionary, one can write reusable styles, DataTemplates, ControlTemplates. One can also define custom definitions for Brush, Color, Background etc.

Each of these custom defined style or template is called as resource and a unique key must be given to each resource.


Steps to add Resource Dictionary

WPF HyperLink Button using Style and Control Template




WPF: HyperLink Button using Style and Control Template

Using this post, you will be able to create a button, which will look like Hyperlink.
To achieve this you need to create a style for a button and in that style you need to modify the template of the button so that it looks like hyperlink.

Also, mostly we see that in hyperlink, the color changes whenever the mouse hovers on it. So using Control Template triggers, we will change the foreground color of the hyperlink.

Here is the Hyperlink button style which you need to define in the Resources section of XAML.


WPF: Image Button using Control Template



WPF: Image Button using Control Template

In WPF, for better UI representation we mostly use images in our application.
So most common place where we use images is in place of buttons.
Mostly we represent action buttons such as add,delete etc with some image which represents add or delete functionality.

Here we have taken an example of Add button and we have used Control Template for modifying the button to show as image instead of normal button.