First, resource dictionary

A common project must have styles and templates that need to be reused. In WPF, you can use a resource dictionary to write common styles, and then introduce a resource dictionary into the page to implement style inheritance

1. Create a new dictionary

First add a system.xAML reference, then create a new WPF named GlobalStyle.xamL.xAML, then manually remove Globalstyle.xaml.cs, rewrite GlobalStyle.xAML as a resource dictionary file format, and then implement a sure button style

The new dictionary

<ResourceDictionary  x:Class="_002_Global_Style.GlobalStyle"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:local="clr-namespace:_002_Global_Style"
        mc:Ignorable="d"> <! < p Style = "margin-top: 1em; margin-bottom: 1em"alert_style_sure_btn" TargetType="Label">
        <Setter Property="Width" Value="120"></Setter>
        <Setter Property="Height" Value="40"></Setter>
        <Setter Property="Padding" Value="0"></Setter>
        <Setter Property="Margin" Value="0,20,0,0"></Setter>
        <Setter Property="FontSize" Value="14"></Setter>
        <Setter Property="Cursor" Value="Hand"></Setter>
        <Setter Property="Background" Value="#FFEC8E72"></Setter>
        <Setter Property="Foreground" Value="White"></Setter>
        <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
        <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
    </Style>
</ResourceDictionary>
Copy the code

2. The plug-in hosts the page

Create a new WPF control named container.xaml to serve as the hosting page for the plug-in’s content, introduce the global resource dictionary, and then create a Label Label specifying the Style as AlerT_STYLE_SURE_bTN in the global Style

<! --#region style, template resources -->
<UserControl.Resources>
    <ResourceDictionary Source="GlobalStyle.xaml"></ResourceDictionary> </UserControl.Resources> <! --#endregion-->

<StackPanel>
    <Label Style="{DynamicResource alert_style_sure_btn}"</Label> </StackPanel>Copy the code

3. Preview the results

preview

2. Associate WPF

1. Declare static UI object properties in main. cs and initialize them in OnLoad

public static Container container; Container = new container ();Copy the code

2, add WindowsFormsIntegration reference, code into System. At the same time. Windows Forms. The Integration library 3, using ElementHost WinForm invokes the WPF

/ / WinForm is associated with WPF (in WinElementHost element = new ElementHost(); element.Child = container; element.Dock = DockStyle.Fill;Copy the code

4. Add UI objects to Fiddler’s Page

// Add the WPF mount object to the page.controls.add (element);Copy the code

Package debugging results

The results of

Series of articles

  • A, Hello World
  • Global styles
  • Static pages
  • 4. Data layer
  • Global events
  • The HOST event
  • 7. HOST mapping
  • Eight, to optimize
  • Executable files

Resources to recommend

  • Fiddler plug-in development guide source code
  • Fiddler – FPlug plug-in
  • Whistle. FPlug plug-in