1 / 24

Resources and Styles

Learn how to efficiently manage resources and create stylish interfaces in WPF to streamline code and enhance maintainability and adaptability. Dive into advanced techniques for creating and applying styles dynamically.

wcora
Download Presentation

Resources and Styles

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Resources and Styles RujchaiUng-arunyawee Department of Computer Engineering KhonKaen University

  2. WPF Resources • Assembly resources • Object resources. (aka. Logical or Declarative resources)

  3. Object Resources • Efficiency. • Resources let you define an object once and use it in several places in your markup. This streamlines your code and makes it marginally more efficient. • Maintainability. • Resources let you take low-level formatting details (such as font sizes) and move them to a central place where they’re easy to change. It’s the XAML equivalent of creating constants in your code. • Adaptability. • Once certain information is separated from the rest of your application and placed in a resource section, it becomes possible to modify it dynamically. For example, you may want to change resource details based on user preferences or the current language.

  4. The Resources Collection • Every element includes a Resources property, which stores a dictionary collection of resources. • The most common way to define resources is at the window-level

  5. Use a resource in your XAML • By a markup extension • StaticResource: set once, when the window is first created. • DynamicResource: reapplied if the resource is changed

  6. Accessing Resources in Code

  7. Application Resources • WPF continues to check the set of resources you’ve defined for your application the App.xaml file

  8. System Resources • SystemColors, SystemFonts, and SystemParameters

  9. Styles • A style is a collection of property values that can be applied to an element. • Similar to the cascading style sheet (CSS) standard in HTML • The Style class is used to create styles.

  10. Properties of The Style Class

  11. Create a Style at object level

  12. Setting Complex Properties

  13. Creating a button-only style

  14. Attaching Event Handlers

  15. Many Layers of Styles

  16. Automatically Applying Styles • Simply need to set the TargetType property to indicate the appropriate type and leave out the key name altogether.

  17. Sets the Style property to a null value is to remove the style.

  18. The Style.Triggers: Trigger • Using triggers, you can automate simple style changes without resorting to code

  19. Multiple Triggers

  20. The Style.Triggers: EventTrigger • Simple Trigger waits for a property change to occur • Event Trigger waits for a specific event to be fired • Event trigger requires that you supply a series of actions that modify the control • These actions are used to apply an animation.

More Related