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

Exception: "Value does not fall within the expected range".

3 Answers 303 Views
Window
This is a migrated thread and some comments may be shown as answers.
T.Y.
Top achievements
Rank 1
T.Y. asked on 02 Jun 2009, 10:14 AM
I have two user controls that contain the radwindow

<UserControl xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"  x:Class="MyApplication.MyForm" 
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:extp="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls" 
    xmlns:ext="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"      
    Width="Auto" Height="Auto">  
    <Grid x:Name="LayoutRoot" Width="Auto" Height="Auto">  
         <telerikNavigation:RadWindow x:Name="form" WindowStartupLocation="CenterScreen" IconTemplate="{x:Null}" ResizeMode="CanMaximize">  
        <Grid Height="Auto" Width="Auto" Margin="2,2,2,2">  
                    <Grid.RowDefinitions> 
                        <RowDefinition Height="0.918*"/>  
                        <RowDefinition Height="0.082*"/>  
                    </Grid.RowDefinitions> 
                    <Button x:Name="cancelButton1" HorizontalAlignment="Right"   Grid.Row="1"  Height="25" Width="70"  /> 
                    <Button x:Name="okButton" Width="70"   Grid.Row="1" Height="25"\> 
                    <Grid x:Name="content" Margin="0,0,0,0">    
                    </Grid> 
    </Grid> 
  </telerikNavigation:RadWindow> 
 </Grid> 
 
 
<UserControl xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"  x:Class="MyApplication.MyDialog" 
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:extp="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls" 
    xmlns:ext="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"      
    Width="Auto" Height="Auto">  
    <Grid x:Name="LayoutRoot" Width="Auto" Height="Auto">  
         <telerikNavigation:RadWindow x:Name="dialog" WindowStartupLocation="CenterScreen" IconTemplate="{x:Null}" ResizeMode="CanMaximize">  
        <Grid Height="Auto" Width="Auto" Margin="2,2,2,2">  
                    <Grid.RowDefinitions> 
                        <RowDefinition Height="0.918*"/>  
                        <RowDefinition Height="0.082*"/>  
                    </Grid.RowDefinitions> 
                    <Button x:Name="cancelButton1" HorizontalAlignment="Right"   Grid.Row="1"  Height="25" Width="70"  /> 
                    <Button x:Name="okButton" Width="70"   Grid.Row="1" Height="25"\> 
                    <TextBlock x:Name="message" Margin="0,0,0,0">    
                    </TextBlock> 
    </Grid> 
  </telerikNavigation:RadWindow> 
 </Grid> 
                                           

when the two windows need to be displayed, I get the exception: "Value does not fall within the expected range".
 I got the expected  because they contain elements with the same name.
when only one RadWindow is displayed, I do not receive an exception.
why is it impossible to define 2 diferrent classes (user control) that contains a RadWindow control with same name?

Thanks
Toiby

3 Answers, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 02 Jun 2009, 02:21 PM
Hello T.Y.,

You receive the error, because the RadWindow control is shown in a Popup control. When you call Show or ShowDialog, it is moved out of the UserControl you put it in and it is placed in a Popup control. All the popups share the same name scope, so you cannot put elements with the same names in popups.

Regards,
Miroslav Nedyalkov
the Telerik team

Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
0
Alex
Top achievements
Rank 1
answered on 23 Mar 2010, 07:59 AM
I have the same problem and I found a workaround. A name of control inside a RadWindow is needed to get access to this control in code-behind. So we have to emulate this somehow. My solution consists of several parts:
1. Custom attached property to specify control "name" in XAML.
<TextBox Utils:NameUtils.CustomName="textBox1" /> 

2. A field for this control in codebehind. We must mark it somehow as such field - I use a custom attribute for this. A name of the field must be the same as the "name" in XAML.
[CustomName] 
public TextBox textBox1; 

3. A place to bound the named control to field. I call an extension method in user control's constructor to do it. This method finds all attribute-marked fields in our user control with reflection and for each field it finds a control in user control's visual tree that has the same "name". Then it assigns founded control to field.
public SilverlightControl2() 
    InitializeComponent(); 
    this.InitializeCustomName(); 


4. Now we can use our initialized field in codebehind.
textBox1.Text = "zzzz1"

I have attached a sample project that implements this solution to this support ticket: http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=292995. Hope this helps somebody. :)



0
Miroslav Nedyalkov
Telerik team
answered on 23 Mar 2010, 01:01 PM
Hello Alex,

 Thank you for your suggestion! It looks good, but I would suggest you to something different - you don't need to create user control and to add RadWindow in it - you could either create a UserControl and every time you need to show it as window to create a new window and set it as a content or to create a user control and to change to root tag to RadWindow instead of UserControl. 

The attached files contains your example code (if someone prefers to use the work-around you shared with us) and the source code that demonstrates both approaches I suggested.

All the best,
Miroslav Nedyalkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Window
Asked by
T.Y.
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
Alex
Top achievements
Rank 1
Share this question
or