Controls in InlineUIContainer & BlockUIContainer a

2019-07-26 16:37发布

问题:

For example if i have code like the following both Buttons are disabled:

<RichTextBox>
    <FlowDocument>
        <BlockUIContainer>
            <Button Content="!"/>
        </BlockUIContainer>
        <Paragraph>
            <InlineUIContainer>
                <Button Content="!"/>
            </InlineUIContainer>
        </Paragraph>
    </FlowDocument>
</RichTextBox>

I have no idea why this is the case or what i can do to prevent this, obviously disabled buttons are not very useful so any help to resolve this would be appreciated.

Edit: It turns out that the FlowDocument gets disabled for some reason, however i have not found a way to reenable it yet, since it changes back to IsEnabled="False" immediately...

回答1:

There actually is a property called IsDocumentEnabled (.NET 3.5 onwards) on the RichTextBox itself that can be set to true to enable the document.



回答2:

You might need to make your custom flowdocument and override its IsEnabledCore property. Check this link out - http://learnwpf.com/post/2007/01/18/When-I-add-Controls-to-a-WPF-RichTextBox-They-Are-Always-Disabled-How-can-I-change-that.aspx

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