Controls in InlineUIContainer & BlockUIContainer always disabled in RichTextBox.Document

时光毁灭记忆、已成空白 提交于 2019-12-11 09:55:50

问题


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;
        }
    }
}


来源:https://stackoverflow.com/questions/5684028/controls-in-inlineuicontainer-blockuicontainer-always-disabled-in-richtextbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!