是否可以自定义 AvalonEdit 搜索面板按钮图标?

问题描述 投票:0回答:1

我需要自定义下拉搜索面板以匹配我的应用程序,但我似乎可以弄清楚如何做。我正在使用 C# WPF .net Framework 4.7.2

我尝试过以下样式,但它无法识别 AvalonEdit 中的搜索。

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

我拥有的选项图片

wpf avalonedit
1个回答
0
投票

对于子孙后代来说,你已经很接近了。 您还必须更新控制模板。 这是我使用的(我引用了 Actipro 主题和一些自定义控件,因此您需要将其明显删除并放入您的)。

然后要使用它,只需将其放入您的资源中

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,0,5,0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Top"
                        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"
                                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"
                                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"
                                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}}"
                                    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>
© www.soinside.com 2019 - 2024. All rights reserved.