1. Prohibition/effectiveness

Add public static method changeRuleEnableByIndex to Main

Public void changeRuleEnableByIndex(int index) {HostModel Rule = mainData[index] as HostModel;  Rule.Enable =! rule.Enable; / / to write to the file DataTool. WriteConfigToFile (); }Copy the code

Create a New GlobalEvent class, add partial prefix, and add the private changeRuleEnable method

Private void changeRuleEnable(Object Sender, MouseButtonEventArgs e) { int index = Convert.ToInt32((sender as Rectangle).Tag.ToString()); / / the status. The Main changeRuleEnableByIndex (index); }Copy the code

Change the event binding class in GlobalStyle.xaml to GlobalEvent 4 and add MouseLeftButtonDown to the checkbox

<Rectangle Grid.Column="2" Tag="{Binding Path=Index}" MouseLeftButtonDown="changeRuleEnable" Visibility="{Binding Path=CheckHide}" Style="{StaticResource content_style_rect}"></Rectangle>
<Canvas Grid.Column="2" Width="12" Height="12" Visibility="{Binding Path=CheckShow}">
    <Path Fill="#FFEC8E72" Data="M10.125 1.5l-5.625 5.625-2.625-2.625-1.875 1.875 4.5 4.5 7.5-7.5z" />
</Canvas>
<Rectangle Grid.Column="2" Tag="{Binding Path=Index}" MouseLeftButtonDown="changeRuleEnable" Visibility="{Binding Path=CheckShow}" Style="{StaticResource content_style_rect_check}"></Rectangle>
Copy the code

5. Pack preview

Prohibition/entry into force

Second, double-click to modify

HostAlertUI constructor: add _index to HostAlertUI constructor and set the default value to -1

private int _index;
public HostAlertUI(int index = -1)
{
    _index = index;

    InitializeComponent();
}
Copy the code

3. HostAlertUI adds initInputText method and calls it in constructor

Region Initializes the contents of the input box
private void initInputText() {// If the value is less than 0, the new value is addedif (_index < 0)
    {
        return; } HostModel rule = main.mainData [_index] as HostModel; // Set data this.ip.Text = rule-ip; this.port.Text = rule.Port; this.url.Text = rule.Url; }#endregion
Copy the code

4, add public static method modifyRuleByIndex to Main class

Public static void modifyRuleByIndex(int index, string IP, string port, HostModel rule = mainData[index] as HostModel; // Update data rule-ip = IP; rule.Port = port; rule.Url = url; / / to write to the file DataTool. WriteConfigToFile (); }Copy the code

6. Add the index parameter to the showHostAlertUI method of the AlertTool class. Set the default value to -1. 7. Add the private method modifyRule to the GlobalEvent class

Private void modifyRule(object sender, MouseButtonEventArgs e) { int index = Convert.ToInt32((sender as Label).Tag.ToString()); / / show bounced AlertTool. ShowHostAlertUI (index); }Copy the code

8. Bind the corresponding control to a double click event in GlobalStyle

<Label Grid.Column="0" Tag="{Binding Path=Index}" MouseDoubleClick="modifyRule" Content="{Binding Path=IpAndPort}" Template="{StaticResource content_text}"></Label>
<Label Grid.Column="1" Tag="{Binding Path=Index}" MouseDoubleClick="modifyRule" Content="{Binding Path=TipsAndUrl}" Template="{StaticResource content_text}"></Label>
Copy the code

9. Pack preview

Modify the bounced
Modify the results

Three, menus,

1. Right-click the project and select properties, switch to Resource Tab, and click Create Resource File. After creation, switch to image resource, click Add Resource, select Add existing file, and import ICONS modify, Delete, Up, and Down

Add the resource
Modify the properties


<! -- ContextMenu x:Key="menu_rule">
    <MenuItem Header="Change">
        <MenuItem.Icon>
            <Image Source="Resources/modify.png" Width="16" Height="16"></Image>
        </MenuItem.Icon>
    </MenuItem>
    <MenuItem Header="Delete">
        <MenuItem.Icon>
            <Image Source="Resources/delete.png" Width="16" Height="16"></Image>
        </MenuItem.Icon>
    </MenuItem>
    <Separator></Separator>
    <MenuItem Header="上移">
        <MenuItem.Icon>
            <Image Source="Resources/up.png" Width="16" Height="16"></Image>
        </MenuItem.Icon>
    </MenuItem>
    <MenuItem Header="Down">
        <MenuItem.Icon>
            <Image Source="Resources/down.png" Width="16" Height="16"></Image>
        </MenuItem.Icon>
    </MenuItem>
</ContextMenu>
Copy the code

4. Bind the corresponding control with ContextMenu property in GlobalStyle

<Label Grid.Column="0" Tag="{Binding Path=Index}" MouseDoubleClick="modifyRule" Content="{Binding Path=IpAndPort}" ContextMenu="{StaticResource menu_rule}" Template="{StaticResource content_text}"></Label>
<Label Grid.Column="1" Tag="{Binding Path=Index}" MouseDoubleClick="modifyRule" Content="{Binding Path=TipsAndUrl}" ContextMenu="{StaticResource menu_rule}" Template="{StaticResource content_text}"></Label>
Copy the code

5. Pack preview

Rules of the menu

4. Menu — modify

The GlobalEvent class adds the private handleRuleMenuClick method

# Region menu click event
private void handleRuleMenuClick(object sender, RoutedEventArgs e)
{
    string type= (sender as MenuItem).Tag.ToString(); object target = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as object; Int index = (int)(target as Label).tag;if (type= ="modify") { modifyRule(target, null); }}#endregion
Copy the code

Modify the menu Item binding Click and set the Tag to modify

<MenuItem Header="Change" Click="handleRuleMenuClick" Tag="modify">
    <MenuItem.Icon>
        <Image Source="Resources/modify.png" Width="16" Height="16"></Image>
    </MenuItem.Icon>
</MenuItem>
Copy the code

Menu – delete

Add public static method deleteRuleByIndex to Main

Rule public static void deleteRuleByIndex(int index) {mainData.removeat (index); // iterate to modify the subscript valuefor(int i = 0, len = mainData.Count; i < len; i++) { HostModel item = mainData[i] as HostModel; item.Index = i; } / / to write to the file DataTool. WriteConfigToFile (); }Copy the code

Add the public deleteRuleFromUI method to the Container class

/ / delete Rule controls public void deleteRuleFromUI (int index) {this. Host. Children. The RemoveAt (index); }Copy the code

Add delete logic to GlobalEvent handleRuleMenuClick

else if (type= ="delete") {// Delete data main.deleterulebyIndex (index); / / delete the corresponding to the Main UI. Container. DeleteRuleFromUI (index); }Copy the code

4. Bind the Click attribute to the delete menu Item in GlobalStyle and set the Tag to delete

<MenuItem Header="Delete" Click="handleRuleMenuClick" Tag="delete">
    <MenuItem.Icon>
        <Image Source="Resources/delete.png" Width="16" Height="16"></Image>
    </MenuItem.Icon>
</MenuItem>
Copy the code

Menu – move up/down

Add public static method moveRuleByType to Main

Public static void moveRuleByType(int index, string moveType)if (index == 0 && moveType == "up")
    {
        return; } // Last dataif (index == mainData.Count - 1 && moveType == "down")
    {
        return; } // Move dataif (moveType == "up")
    {
        mainData.Insert(index - 1, mainData[index]);
        mainData.RemoveAt(index + 1);
    }
    else{ mainData.Insert(index, mainData[index + 1]); mainData.RemoveAt(index + 2); } // iterate over the subscript valuesfor(int i = 0, len = mainData.Count; i < len; i++) { HostModel item = mainData[i] as HostModel; item.Index = i; } / / to write to the file DataTool. WriteConfigToFile (); }Copy the code

2. Add the private initRuleToUI method to the Container class

#region private method (internal tool method)// Initialize the Rule panel private voidinitRuleToUI() { ArrayList items = Main.mainData; // Iterate to add the Rule to the UIfor(int i = 0, len = items.Count; i < len; i++) { addHostRule(items[i] as HostModel); }}#endregion
Copy the code

Add the public moveRuleFromUI method to the Container class

Public void moveRuleFromUI(int index, string moveType) {if (index <= 0 && moveType == "up")
    {
        Fiddler.FiddlerApplication.DoNotifyUser("Already at the top."."Can't move up.");
        return;
    }

    StackPanel panel = this.host;

    if (index == panel.Children.Count - 1 && moveType == "down")
    {
        Fiddler.FiddlerApplication.DoNotifyUser("Already at the bottom."."Can't move down.");
        return; } // Remove all Item panel.children.clear (); // re-render all Item initRuleToUI(); }Copy the code

Add up/ Down logic to The GlobalEvent class handleRuleMenuClick

else if (type= ="up" || type= ="down") {// Move the corresponding data main.moveruleByType (index,type); / / move the corresponding UI Main. Container. MoveRuleFromUI (index,type);
}
Copy the code

5. Bind the Click attribute to the move up/down menu Item in GlobalStyle and set the Tag to up/ Down

<MenuItem Header="上移" Click="handleRuleMenuClick" Tag="up">
    <MenuItem.Icon>
        <Image Source="Resources/up.png" Width="16" Height="16"></Image>
    </MenuItem.Icon>
</MenuItem>
<MenuItem Header="Down" Click="handleRuleMenuClick" Tag="down">
    <MenuItem.Icon>
        <Image Source="Resources/down.png" Width="16" Height="16"></Image>
    </MenuItem.Icon>
</MenuItem>
Copy the code

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