天天看點

Fiddler插件開發指南(二、全局樣式)

這裡寫目錄标題

    • 一、資源字典
      • 1、建立字典
      • 2、插件承載頁面
      • 3、預覽結果
    • 二、關聯WPF
    • 三、打包調試結果
    • 四、系列文章彙總
    • 五、資源推薦

一、資源字典

一般項目肯定存在需要複用的樣式和模闆,在WPF中可以使用資源字典來實作公共樣式的編寫,然後在頁面中引入資源字典即可實作樣式繼承

1、建立字典

首先添加System.Xaml引用,接着建立一個WPF,命名為GlobalStyle.xaml,然後手動删除掉GlobalStyle.xaml.cs,将GlobalStyle.xaml重新編寫為資源字典檔案格式,接着實作一個确定按鈕樣式

Fiddler插件開發指南(二、全局樣式)
<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" >
    <!-- 确定按鈕 -->
    <Style x:Key="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>
           

2、插件承載頁面

建立一個WPF控件,命名為Container.xaml,作為插件内容的承載頁面,然後引入全局資源字典,接着建立一個Label标簽,指定Style為全局樣式中的alert_style_sure_btn

<!--#region 樣式、模闆資源 -->
<UserControl.Resources>
    <ResourceDictionary Source="GlobalStyle.xaml"></ResourceDictionary>
</UserControl.Resources>
<!--#endregion-->

<StackPanel>
    <Label Style="{DynamicResource alert_style_sure_btn}">确定</Label>
</StackPanel>
           

3、預覽結果

Fiddler插件開發指南(二、全局樣式)

二、關聯WPF

1、在Main.cs檔案中,申明靜态UI對象屬性,同時在OnLoad中初始化

public static Container container;
//建立UI對象
container = new Container();
           

2、添加WindowsFormsIntegration引用,同時代碼引入System.Windows.Forms.Integration庫

3、使用ElementHost實作在WinForm中調用WPF

//将WinForm和WPF聯系起來(在WinForm中調用WPF)
ElementHost element = new ElementHost();
element.Child = container;
element.Dock = DockStyle.Fill;
           

4、将UI對象添加進Fiddler插件的Page中

//将WPF挂載對象添加到page中
page.Controls.Add(element);
           

三、打包調試結果

Fiddler插件開發指南(二、全局樣式)

四、系列文章彙總

  • 一、Hello World
  • 二、全局樣式
  • 三、靜态頁面
  • 四、資料層
  • 五、全局事件
  • 六、HOST事件
  • 七、HOST映射
  • 八、優化
  • 九、可執行檔案

五、資源推薦

  • Fiddler插件開發指南源碼
  • Fiddler-FPlug插件
  • whistle.FPlug插件