Frank
Frank

Reputation: 21

Is it possible to customize the AvalonEdit search panel button icons?

I need to customize the dropdown search panel to match my application but I can seem to figure out how. I am using C# WPF .net Framework 4.7.2

I have tried the below style but it does not recognize Search in AvalonEdit.

xmlns:search="clr-namespace:ICSharpCode.AvalonEdit.Search"
<Style TargetType="search:SearchPanel">

Image of options I have

Upvotes: 0

Views: 303

Answers (1)

b.pell
b.pell

Reputation: 4298

For posterity, you were close. You have to update the Control Template also. Here is what I use (I'm referencing Actipro themes and some custom controls so you would need to remove that obviously and put yours in).

Then to use this it just needs to be put into your resources MergedDictionaries.

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
    xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
    xmlns:themes="http://schemas.actiprosoftware.com/winfx/xaml/themes">
    <!--  Search Panel  -->
    <Style TargetType="avalonedit:SearchPanel">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type avalonedit:SearchPanel}">
                    <Border
                        Margin="0,5,0,0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Top"
                        BorderBrush="{DynamicResource {x:Static themes:AssetResourceKeys.WindowTitleBarButtonBorderActiveHoverBrushKey}}"
                        BorderThickness="1,1,1,1"
                        Cursor="Arrow">
                        <StackPanel Orientation="Horizontal">
                            <StackPanel.Resources>
                                <Style TargetType="Button">
                                    <Style.Resources>
                                        <Style TargetType="Border">
                                            <Setter Property="CornerRadius" Value="0" />
                                        </Style>
                                    </Style.Resources>
                                </Style>
                                <Style TargetType="ToggleButton">
                                    <Style.Resources>
                                        <Style TargetType="Border">
                                            <Setter Property="CornerRadius" Value="0" />
                                        </Style>
                                    </Style.Resources>
                                </Style>
                            </StackPanel.Resources>
                            <TextBox
                                Name="PART_searchTextBox"
                                Width="150"
                                Height="Auto"
                                Margin="5,5,0,5"
                                BorderBrush="{DynamicResource {x:Static themes:AssetResourceKeys.WindowTitleBarButtonBorderActiveHoverBrushKey}}"
                                Focusable="True">
                                <TextBox.Text>
                                    <Binding
                                        Path="SearchPattern"
                                        RelativeSource="{RelativeSource TemplatedParent}"
                                        UpdateSourceTrigger="PropertyChanged">
                                        <Binding.ValidationRules>
                                            <ExceptionValidationRule />
                                        </Binding.ValidationRules>
                                    </Binding>
                                </TextBox.Text>
                            </TextBox>

                            <!--  FindNext button  -->
                            <Button
                                Width="30"
                                Height="22"
                                Margin="3,1,0,1"
                                Padding="0"
                                Command="avalonedit:SearchCommands.FindNext"
                                Style="{DynamicResource {x:Static themes:SharedResourceKeys.ButtonBaseStyleKey}}"
                                ToolTip="{Binding Localization.FindNextText, RelativeSource={RelativeSource TemplatedParent}}">

                                <shared:DynamicImage
                                    Width="14"
                                    Height="14"
                                    Source="../Assets/vs-find-next-16.png" />
                            </Button>

                            <!--  FindPrevious (set visibility if required) button  -->
                            <Button
                                Width="30"
                                Height="22"
                                Margin="0"
                                BorderBrush="Transparent"
                                BorderThickness="0"
                                Command="avalonedit:SearchCommands.FindPrevious"
                                Style="{DynamicResource {x:Static themes:SharedResourceKeys.ButtonBaseStyleKey}}"
                                ToolTip="{Binding Localization.FindPreviousText, RelativeSource={RelativeSource TemplatedParent}}"
                                Visibility="Collapsed">
                                <shared:DynamicImage Source="../Assets/vs-find-previous-16.png" />
                            </Button>

                            <StackPanel Orientation="Horizontal">
                                <ToggleButton
                                    Width="30"
                                    Height="22"
                                    Margin="1,0,0,0"
                                    Content="aA"
                                    Cursor="Hand"
                                    FontFamily="Consolas,Courier New,Courier"
                                    FontSize="12"
                                    FontWeight="Normal"
                                    IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}"
                                    Style="{DynamicResource {x:Static themes:SharedResourceKeys.ButtonBaseStyleKey}}"
                                    ToolTip="{Binding Localization.MatchCaseText, RelativeSource={RelativeSource TemplatedParent}}" />

                                <ToggleButton
                                    Width="30"
                                    Height="22"
                                    Margin="1,0,0,0"
                                    Content="Ab"
                                    Cursor="Hand"
                                    FontFamily="Consolas,Courier New,Courier"
                                    FontSize="12"
                                    FontWeight="Normal"
                                    IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}"
                                    Style="{DynamicResource {x:Static themes:SharedResourceKeys.ButtonBaseStyleKey}}"
                                    ToolTip="{Binding Localization.MatchWholeWordsText, RelativeSource={RelativeSource TemplatedParent}}" />

                                <ToggleButton
                                    Width="30"
                                    Height="22"
                                    Margin="1,0,0,0"
                                    Content="a*"
                                    Cursor="Hand"
                                    FontFamily="Consolas,Courier New,Courier"
                                    FontSize="12"
                                    FontWeight="Normal"
                                    IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}"
                                    Style="{DynamicResource {x:Static themes:SharedResourceKeys.ButtonBaseStyleKey}}"
                                    ToolTip="{Binding Localization.UseRegexText, RelativeSource={RelativeSource TemplatedParent}}" />
                            </StackPanel>

                            <!--  Search Panel close button  -->
                            <Button
                                Width="30"
                                Height="22"
                                Margin="1,0,4,0"
                                Padding="1"
                                Command="avalonedit:SearchCommands.CloseSearchPanel"
                                Style="{DynamicResource {x:Static themes:SharedResourceKeys.ButtonBaseStyleKey}}"
                                ToolTip="Close">

                                <shared:DynamicImage
                                    Width="14"
                                    Height="14"
                                    Source="../Assets/vs-close-16.png" />
                            </Button>
                        </StackPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>

Upvotes: 0

Related Questions