Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
105
xamDateTimeEditor throws an StackOverflowException
posted

Hello,

 

I am using xamDateTimeEditor in a MVVM application. So, the xamDateTimeEditor is standalone and TwoWay binded to a datetime property in my viewModel. When the xamDateTimeEditor gets focused, it throws an StackOverflowException. Here is my code :

<

 

igEditors:XamDateTimeEditor x:Name="myDateTimeEditor" Value="{Binding myDate}"/>

When i remove this line it works. Am I doing something wrong? Thank you for your help.

Parents Reply
  • 54937
    Offline posted in reply to Aidoud

    Sorry. I was able to reproduce the issue with your sample but it seems like it's ultimately a bug in the WPF framework relating to focus scopes. I was able to strip down your sample such that it doesn't use any of our stuff. Basically since you are setting the Content of the UserControl to an element (a stackpanel in this case), that Content becomes a logical child of the UserControl. When an element is in a focusscope and its logical parent is in a different focus scope the wpf framework gets into this state and causes the stackoverflowexception.

    In your original case the focusscope is the ContentPane. That contentpane ultimately contains the Content of the usercontrol because your default template for your UserControl contains the dockmanager which contains the contentpane and the contentpane's content is bound to the content of the usercontrol. The only workarounds I can think of are to set the FocusManager.IsFocusScope of the ContentPane to false or to override OnContentChanged of the usercontrol and don't call the base implementation so it doesn't get added as a logical child and override the LogicalChildren so it returns an empty enumerator.

    There are downsides to both I would think. The ContentPane expects and is tested as being a focus scope so you could hit issues later with it not being a focus scope. With the other approach, the UserControl may assume its Content is a logical child (as it does in the logicalchildren which is why you need to override that as well).

    I've attached a modified version of your sample which takes the latter approach. If you run the application as is and click the button you will get the exception. If you go to UserControlWithAButton and uncomment the OnContentChanged and LogicalChildren overrides and rerun it the problem doesn't happen.

    IssueReproduction.zip
Children