简体   繁体   中英

System.InvalidCastException: 'Unable to cast object of type 'System.Windows.Documents.FlowDocument' to type 'System.Windows.Media.Visual'.'

<ad:DockingManager>
        <ad:LayoutRoot>
            <ad:LayoutPanel Orientation="Horizontal">
                <ad:LayoutPanel>

                    <ad:LayoutDocumentPaneGroup>
                        <ad:LayoutDocumentPane >
                            <ad:LayoutDocument>
                                <RichTextBox>Here is Error!!!</RichTextBox>
                            </ad:LayoutDocument>
                        </ad:LayoutDocumentPane>
                    </ad:LayoutDocumentPaneGroup>
                </ad:LayoutPanel>
                <ad:LayoutPanel>
                    <ad:LayoutAnchorablePaneGroup>
                        <ad:LayoutAnchorablePane>
                            <ad:LayoutAnchorable>
                                <RichTextBox x:Name="achorRichText"></RichTextBox>
                                </ad:LayoutAnchorable>
                        </ad:LayoutAnchorablePane>
                    </ad:LayoutAnchorablePaneGroup>
                </ad:LayoutPanel>
                </ad:LayoutPanel>         
        </ad:LayoutRoot>
    </ad:DockingManager>

I am learning C# using Visual Studio. I am trying to use Xceed Avalondoc. I used a RichTextBox in a LayoutDocument tag. It give this error

System.InvalidCastException: 'Unable to cast object of type 'System.Windows.Documents.FlowDocument' to type 'System.Windows.Media.Visual'.'

when I click in the RichTextBox after program runs.

Can you help me remove this error. Thanks

So long story short I found the reason and the solution to this strange problem.

Actually I was using the latest version of Xceed AvalonDock in my new project and It has a bug. I found an old version 2.0.0 of AvalonDock & it worked. I have following specifications in my Project.

  1. Visual Studio Enterprise 2019
  2. WPF Framework Project
  3. .Net Framework 4.7.2
  4. Avalon.Wpf.Toolkit version 1.9

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM