This is a migrated thread and some comments may be shown as answers.

ShowDialog and Show methods throw exception

2 Answers 148 Views
Window
This is a migrated thread and some comments may be shown as answers.
Alexey
Top achievements
Rank 2
Alexey asked on 21 Oct 2009, 10:39 AM
Hi,

I've get following error.

{System.ArgumentException: Value does not fall within the expected range.
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.Collection_InsertValue[T](PresentationFrameworkCollection`1 collection, UInt32 index, CValue value)
   at MS.Internal.XcpImports.Collection_InsertDependencyObject[T](PresentationFrameworkCollection`1 collection, UInt32 index, DependencyObject value)
   at System.Windows.PresentationFrameworkCollection`1.InsertDependencyObject(Int32 index, DependencyObject value)
   at System.Windows.Controls.UIElementCollection.InsertInternal(Int32 index, UIElement value)
   at System.Windows.PresentationFrameworkCollection`1.Insert(Int32 index, T value)
   at Telerik.Windows.Controls.HACKS.AttachPopupToVisualTree(Popup popup)
   at Telerik.Windows.Controls.PopupManager.Open(Popup popup, Boolean attachToVisualRoot)
   at Telerik.Windows.Controls.PopupManager.OpenWindow(Popup popup, Boolean attachToVisualRoot)
   at Telerik.Windows.Controls.PopupManager.Open(Popup popup, PopupType type, Boolean attachToVisualRoot)
   at Telerik.Windows.Controls.PopupManager.Open(Popup popup, PopupType type)
   at Telerik.Windows.Controls.RadWindowPopup.WindowPopupSilverlightFactory.WindowPopupSilverlightImpl.Show()
   at Telerik.Windows.Controls.RadWindowPopup.WindowPopupSilverlightFactory.WindowPopupSilverlightImpl.OpenPopup()
   at Telerik.Windows.Controls.RadWindowPopup.WindowPopup.Open(Boolean isModal)
   at Telerik.Windows.Controls.RadWindow.ShowWindow(Boolean modal)
   at Telerik.Windows.Controls.RadWindow.Show()
   at Witcraft.Halcyone.Administration.Modules.Forms.AddOrUpdateItemDialog.Show()
   at Witcraft.Halcyone.Presentation.DialogWindowService.Show[TView,TModel]()
   at Witcraft.Halcyone.Administration.Modules.Forms.GenericFormViewModel`2.OnOpenUpdateItemDialogCommand(Object value)
   at Witcraft.Halcyone.Presentation.Commands.DelegateCommand`1.Execute(T parameter)
   at Witcraft.Halcyone.Presentation.Commands.DelegateCommand`1.System.Windows.Input.ICommand.Execute(Object parameter)
   at Witcraft.Halcyone.Presentation.Commands.InvokeDelegateCommandAction.Invoke(Object parameter)
   at System.Windows.Interactivity.TriggerAction.CallInvoke(Object parameter)
   at System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
   at Witcraft.Halcyone.Presentation.Commands.CommandEventTrigger.OnEventFired(Object sender, EventArgs eventArgs)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}

Show and Show Dialog methods are called from usercontrol that was dynamically created

    public partial class Dialog : UserControl
    {
        public Dialog()
        {
            InitializeComponent();
            window.ShowDialog();
        }
    }




Everything works nice when we use it pure new empty project, but inside our application which has deep control hierarchy it drop that exception.

Thanks,
Alexey Zakharov.

2 Answers, 1 is accepted

Sort by
0
Alexey
Top achievements
Rank 2
answered on 21 Oct 2009, 10:55 AM
<UserControl x:Class="RadWindowExperiment.Dialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:nav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
    >
    <Grid>
        <nav:RadWindow x:Name="window" ModalBackground="#AA000000" WindowStartupLocation="CenterScreen"   >
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="100"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Rectangle Grid.Row="0" Fill="LemonChiffon" Width="100" Height="100"/>
            </Grid>
        </nav:RadWindow>
    </Grid>
</UserControl>

With this hack I've tried to simulate Silverlight ChildWindow behavior when Window is just another usercontrol. But in this case usercontrol are not actually loaded. That is why data binding inside radwindow breaks everything and we get that exception.

What is the best way to use RadWindow as standart ChildWindow?



0
Alexey
Top achievements
Rank 2
answered on 21 Oct 2009, 11:16 AM
I solved the problem!

I've just placed Window as root element.

<nav:RadWindow x:Class="RadWindowExperiment.Dialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:nav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
    x:Name="window" ModalBackground="#AA000000" WindowStartupLocation="CenterScreen"
    >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="100"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Rectangle Grid.Row="0" Fill="LemonChiffon" Width="100" Height="100"/>
    </Grid>
</nav:RadWindow>

Now it starts working OK.


Tags
Window
Asked by
Alexey
Top achievements
Rank 2
Answers by
Alexey
Top achievements
Rank 2
Share this question
or