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

MindRoasterMir
  • 324
  • 1
  • 2
  • 18
  • 2
    Show the code where you are getting this error, may help – TheGeneral Aug 03 '20 at 00:00
  • Thank @TheGeneral for your comment. I just wanted to copy the code but I am now in another problem and want to solve it first. No connection between my xaml & .cs file for unknown reason. trying to solve it. Thanks – MindRoasterMir Aug 03 '20 at 07:15
  • Are you using any of the text boxes in code-behind, like `achorRichText`? If yes, please post the code for that. – thatguy Aug 03 '20 at 08:23
  • @thatguy no I am not using any of the RichTexboxes in code behind. By the way the RichTextBox in anchorable layout works and give no error. thanks – MindRoasterMir Aug 03 '20 at 08:29
  • @MindRoasterMir But `Here is Error!!!` is not the actual content of the `RichTextBox`? The layout as it is without the text does not provoke that error. – thatguy Aug 03 '20 at 08:31
  • @thatguy you are right. It is empty has nothing in it and I get an error when I click in it after program runs. – MindRoasterMir Aug 03 '20 at 08:35
  • @MinRoasterMir A quick test with your XAML (without the text) does not throw an error, even when typing in each of the rich text boxes. – thatguy Aug 03 '20 at 08:39
  • @thatguy strange. where did you get the avalondock from nuget packages ? – MindRoasterMir Aug 03 '20 at 08:42
  • @thatguy also to mention is that i am using – MindRoasterMir Aug 03 '20 at 08:45
  • @MindRoasterMir The error mentions the type `FlowDocument`, which is used in the `RichTextBox` and that is cast to another incompatible type, but that does not seem to be reproducible in the provided XAML code, so I suspect that there must be some code-behind, or other markup that causes the issue. I tested it with `Extended.Wpf.Toolkit`. – thatguy Aug 03 '20 at 19:07
  • @thatguy I have reproduced it in a new empty project. Wpf Framework - Visual Studio Enterprise 2019. Added Xceed Avalondoc from nuget and added only this code in a normal window MainWindow xml, nothing in code behind. ERROR! after running the project & on clicking inside this RichTextBox. Standing & Waiting – MindRoasterMir Aug 03 '20 at 20:47

1 Answers1

1

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

MindRoasterMir
  • 324
  • 1
  • 2
  • 18