1. Description button

Create an AlertUI folder and create a WPF control named explainAlerTui.xaml. Add a new style to globalStyle.xaml

<! < p Style = "margin-top: 1em; margin-bottom: 1em"alert_style_explain" TargetType="TextBlock">
    <Setter Property="Padding" Value="Ten five"></Setter>
    <Setter Property="Foreground" Value="#FF4B4B4B"></Setter> </Style> <! <Style x:Key="alert_style_explain_label" TargetType="Label">
    <Setter Property="Foreground" Value="#FF4B4B4B"></Setter>
    <Setter Property="Padding" Value="0,5,0,0"></Setter>
</Style>
Copy the code

3. Introduce global style files in explainAlertui.xAML and add related element structures

<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Background="White">
    <StackPanel Margin="10, 0">
        <StackPanel x:Name="host">
            <Label HorizontalContentAlignment="Center" Margin="0, 10">HOST mapping description </Label> <TextBlock Style="{StaticResource alert_style_explain}"</TextBlock> <TextBlock Style="{StaticResource alert_style_explain}"</TextBlock> <TextBlock Style="{StaticResource alert_style_explain}"<LineBreak/> <Label XML :space="preserve" Style="{StaticResource alert_style_explain_label}"> (1), not limited to domain name, to map https://www.example.com/testFor example, /index.html </Label><LineBreak/> <Label XML :space="preserve" Style="{StaticResource alert_style_explain_label}"> (2) You can specify a specific Path, for example, www.example.com/test</Label><LineBreak/>
            <Label xml:space="preserve" Style="{StaticResource alert_style_explain_label}"> < span style = "max-width: 100%; clear: both; min-height: 1emtest/i</Label><LineBreak/>
            <Label xml:space="preserve" Style="{StaticResource alert_style_explain_label}"Support regular expressions, such as \S*.example.com</Label> </TextBlock> <TextBlock Style="{StaticResource alert_style_explain}"</TextBlock> <TextBlock Style="{StaticResource alert_style_explain}"</TextBlock> </StackPanel> <Label Height="20"></Label>
    </StackPanel>
</ScrollViewer>
Copy the code

4. Add the AlertTool class to the Tools folder and add the private static method initWindow

Private static Window initWindow(stringtype, int height, int width = 500) { Window window = new Window(); // Set Width and height window.Width = Width; window.Height = height + 30; // The height of the status bar is 30 // Remove the minimize and maximize buttons window.ResizeMode = 0; window.Title =type= ="explain" ? "Configuration Instructions" : "Host configuration"; / / set the display window. In the middle. WindowStartupLocation = WindowStartupLocation CenterScreen; // Returns the corresponding formreturn window;
}
Copy the code

5. Add the public static method showExplainAlertUI to the AlertTool class

Public static void showExplainAlertUI(stringtype) { ExplainAlertUI explainAlertUI = new ExplainAlertUI(); // Initialize the Window Window = initWindow("explain", 450, 700); // Set the window window Content window.Content = explainAlertUI; // Display the window window.showdialog (); }Copy the code

6. Add the private showExplainAlertUI method to the Container class

# region Alert - events/ / show that bounced private void showExplainAlertUI (object sender, MouseButtonEventArgs e) {AlertTool. ShowExplainAlertUI (); }#endregion
Copy the code

7. Bind MouseLeftButtonDown to the description button in the Container control

<Label MouseLeftButtonDown="showExplainAlertUI" Template="{StaticResource top_guide}" HorizontalAlignment="Left"></Label>
Copy the code

8. Pack preview

That bounced

2. Add buttons

Create a new WPF control in the AlertUI folder and name it HostAlerTui.xaml. Create a new style in globalStyle.xaml

<! < p Style = "margin-top: 1em; margin-bottom: 1em"alert_style_title" TargetType="Label">
    <Setter Property="Height" Value="40"></Setter>
    <Setter Property="HorizontalAlignment" Value="Center"></Setter>
    <Setter Property="VerticalAlignment" Value="Top"></Setter>
    <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
    <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
    <Setter Property="FontSize" Value="16"></Setter>
    <Setter Property="Foreground" Value="#FF666666"></Setter>
    <Setter Property="Margin" Value="0,20,0,0"></Setter> </Style> <! < p Style = "margin-top: 1em; margin-bottom: 1em"alert_style_wrap" TargetType="StackPanel">
    <Setter Property="Height" Value="50"></Setter>
    <Setter Property="Orientation" Value="Horizontal"></Setter> </Style> <! -- __TextArea --> <Style x:Key="alert_style_wrap_textarea" TargetType="StackPanel" BasedOn="{StaticResource alert_style_wrap}">
    <Setter Property="Height" Value="110"></Setter> </Style> <! < p Style = "margin-top: 1em; margin-bottom: 1em"alert_style_name" TargetType="Label">
    <Setter Property="Width" Value="80"></Setter>
    <Setter Property="Height" Value="50"></Setter>
    <Setter Property="HorizontalContentAlignment" Value="Right"></Setter>
    <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
    <Setter Property="FontSize" Value="14"></Setter>
    <Setter Property="Margin" Value="30,0,0,0"></Setter>
    <Setter Property="Foreground" Value="#FF666666"></Setter> </Style> <! "> <Style x:Key="alert_style_input" TargetType="TextBox">
    <Setter Property="Width" Value="300"></Setter>
    <Setter Property="Height" Value="30"></Setter>
    <Setter Property="Margin" Value="10,10,0,0"></Setter>
    <Setter Property="Background" Value="{x:Null}"></Setter>
    <Setter Property="Foreground" Value="Black"></Setter>
    <Setter Property="BorderBrush" Value="#FF666666"></Setter>
    <Setter Property="BorderThickness" Value="0,0,0,1"></Setter>
    <Setter Property="VerticalAlignment" Value="Top"></Setter>
    <Setter Property="VerticalContentAlignment" Value="Center"></Setter> </Style> <! -- Input box __TextArea --> <Style x:Key="alert_style_textarea" TargetType="TextBox" BasedOn="{StaticResource alert_style_input}">
    <Setter Property="Height" Value="90"></Setter>
    <Setter Property="TextWrapping" Value="Wrap"></Setter>
    <Setter Property="Padding" Value="0,0,0,5"></Setter> </Style> <! < 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>
Copy the code

3. Introduce the global style file in HostAlertui.xAML, add the related element structure, and finally set the unique Name of the input control as IP, port and URL

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

<StackPanel Background="White">
    <Label Content="Please fill in the relevant configuration" Style="{StaticResource alert_style_title}"></Label>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="295"/>
            <ColumnDefinition Width="100 *"/>
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Column="0" Style="{StaticResource alert_style_wrap}">
            <Label Style="{StaticResource alert_style_name}">IP</Label>
            <TextBox x:Name="ip" Style="{StaticResource alert_style_input}" Width="165"/>
        </StackPanel>
        <StackPanel Grid.Column="1" Style="{StaticResource alert_style_wrap}">
            <Label Style="{StaticResource alert_style_name}" Width="40" Margin="0"> Port </Label> <TextBox x:Name="port" Style="{StaticResource alert_style_input}" Width="75" Margin="10,10,0,0"/>
        </StackPanel>
    </Grid>
    <StackPanel Style="{StaticResource alert_style_wrap_textarea}">
        <Label Style="{StaticResource alert_style_name}">URL</Label>
        <TextBox x:Name="url" Style="{StaticResource alert_style_textarea}"/>
    </StackPanel>
    <Label Style="{StaticResource alert_style_sure_btn}"</Label> </StackPanel>Copy the code

Add private methods addHostRule and inputKeyDown to HostAlertUI

#region Mouse click event
private void addHostRule(object sender, MouseButtonEventArgs e)
{
    string ip = this.ip.Text;
    string port = this.port.Text;
    string url = this.url.Text;

    if (ip.Length == 0)
    {
        Fiddler.FiddlerApplication.DoNotifyUser("Please fill in the IP address"."Input prompt");
        return;
    }

    if (url.Length == 0)
    {
        Fiddler.FiddlerApplication.DoNotifyUser("Please fill in the URL"."Input prompt");
        return; } // add UI main.addhoStrule (IP, port, url); // Close the popbox (this.parent as Window).close (); }#endregion

#region input box key listens for events
private void inputKeyDown(object sender, KeyEventArgs e)
{
    if(e.Key == Key.Enter) { addHostRule(null, null); }}#endregion
Copy the code

Add showHostAlertUI to the AlertTool class

// Display the Host dialog box public static voidshowHostAlertUI() { HostAlertUI hostAlertUI = new HostAlertUI(); // Initialize the Window Window = initWindow("host", 310); // Set the window window Content window.content = hostAlertUI; // Automatic Focus hostAlertui.ip.focus (); // Display the window window.showdialog (); }Copy the code

Add the private method addHost to the Container class

/ / add the Host private void addHost (object sender, MouseButtonEventArgs e) {AlertTool. ShowHostAlertUI (); }Copy the code

Bind the MouseLeftButtonDown event to the new button of the Container

<Label MouseLeftButtonDown="addHost" Style="{StaticResource top_style_operation}"> new < / Label >Copy the code

9. Pack preview

The new play box
The new results

Three, all ban button

Add the disabledAllHostFromData public static method to the Main class

// Disallow all Host rules public static voiddisabledAllHostFromData() {// iterate over the update datafor(int i = 0, len = mainData.Count; i < len; i++) { HostModel item = mainData[i] as HostModel; // Update data item.enable =false; } / / to write to the file DataTool. WriteConfigToFile (); }Copy the code

2. Add the private method disabledAllItem to the Container class

/ / ban all Item private void disabledAllItem (object sender, MouseButtonEventArgs e) {Main. DisabledAllHostFromData (); }Copy the code

3. Bind the MouseLeftButtonDown event to the new button of the Container

<Label MouseLeftButtonDown="disabledAllItem" Style="{StaticResource top_style_operation_disable}"> all banned < / Label >Copy the code

4. Pack preview

Results all banned

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