Technology Sharing

WPF introduces multiple control libraries for use

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Purpose

When designing and developing, part of a control library meets the UI style we want, and the other part comes from another control library. We want to integrate the styles of the two libraries into the same control resource. Simply referencing will cause the original style to be overwritten. This is achieved by setting a global style.

1. Install the control library nuget package: HandyControl, MaterialDesign
insert image description here
2. Introduce the control library style in App.xaml in the global style
insert image description here
3. Create a new Style folder, create a new resource dictionary file GlobalDictionary.xaml in the folder, and introduce it into the global style of the App.xaml file
insert image description here
4. Write the control style in the GlobalDictionary.xaml file
insert image description here
The button style here inherits from the button style in the MaterialDesign control, and this style is declared as a global style for GreenButton

5. Use a style with two control libraries: Here we use a global style inherited from MaterialDesign and the poptip.Content property from HandyControl
insert image description here
insert image description here

Summarize

By introducing a resource file to inherit some styles from another control library and declaring it in the global style, it can be used in all interfaces and some style properties of other controls can be introduced.