Controls in InlineUIContainer & BlockUIContainer a

2019-07-26 15:55发布

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...

2条回答
不美不萌又怎样
2楼-- · 2019-07-26 16:46

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.

查看更多
Bombasti
3楼-- · 2019-07-26 16:49

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;
        }
    }
}
查看更多
登录 后发表回答