C# RichTextBox中的Border.IsMouseOver(RichTextBox中的InlineUIContainer不响应事件/触发器)

C# RichTextBox中的Border.IsMouseOver(RichTextBox中的InlineUIContainer不响应事件/触发器),c#,.net,wpf,wpf-controls,richtextbox,C#,.net,Wpf,Wpf Controls,Richtextbox,假设我有以下几点: <Grid> <Grid.Resources> <Style TargetType="{x:Type Border}"> <Style.Triggers> <Trigger Property="Border.IsMouseOver" Value="true"> <Setter Proper

假设我有以下几点:

<Grid>

    <Grid.Resources>

        <Style TargetType="{x:Type Border}">
            <Style.Triggers>
                <Trigger Property="Border.IsMouseOver" Value="true">
                    <Setter Property="Background" Value="Black" />
                    <Setter Property="BorderBrush" Value="Red" />
                    <Setter Property="BorderThickness" Value="2" />
                    <Setter Property="CornerRadius" Value="7,2,10,2" />
                </Trigger>
                <Trigger Property="Border.IsMouseOver" Value="false">
                    <Setter Property="Background" Value="Black" />
                    <Setter Property="BorderBrush" Value="RoyalBlue" />
                    <Setter Property="BorderThickness" Value="2" />
                    <Setter Property="CornerRadius" Value="7,2,10,2" />
                </Trigger>
            </Style.Triggers>

        </Style>

        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="Margin" Value="7,0,7,1" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Foreground" Value="White" />
        </Style>

        <Style TargetType="{x:Type Run}">
            <Setter Property="FontSize" Value="12" />
        </Style>

    </Grid.Resources>

        <FlowDocument >

            <Paragraph>

                <Span>

                    <Border>

                        <TextBlock>Test</TextBlock>

                    </Border>

                </Span>

            </Paragraph>

        </FlowDocument>

    </RichTextBox>

</Grid>

试验
当边框位于RichTextBox外部时,样式触发器工作得很好,但当它们位于RichTextBox中的InlineUIContainer内部时,样式触发器工作得很好

我可以通过使用MouseOver事件和VisualTreeHelper.HitTest()方法在代码中设置属性来获得所需的行为,但我非常确定这是非常低效的,我不禁认为有更好的方法来实现这一点


如果有人能在这里提供一些指导,我将不胜感激。

我不得不搜索互联网最深和最黑暗的角落来找到这一个,但似乎有一个黑客可以在FlowDocument中为InlineUIElements启用事件:

public class EventEnabledFlowDocument : FlowDocument
{
    protected override bool IsEnabledCore
    {
        get
        {
            return true;
        }
    }
}

请注意,这样做可能会有一些令人讨厌的副作用,但它似乎对我的目的起作用。我注意到的一个副作用是:如果删除InlineUIElement,然后撤消该删除操作,则不会保存事件处理程序。

另一个副作用是,如果将文档保存/加载为xaml字符串,则该属性不起作用!你知道怎么解决这个问题吗?