This is a migrated thread and some comments may be shown as answers.
Null exception
4 Answers 87 Views
This is a migrated thread and some comments may be shown as answers.
Artur
Top achievements
Rank 1
Artur asked on 07 Jul 2010, 10:59 AM
Hi,

I'm trying to make one custom controller that extends the RadWindow. This controller will have 2 different zones: 1 is the content and the second one footer.
So, to do this, i tried to change the dataTemplate of the content.
 <telerik:RadWindow.Resources> 
         
        <ResourceDictionary>        
             
            <DataTemplate x:Key="ChangedTemplate"
                <Grid> 
                    <Grid.RowDefinitions> 
                        <RowDefinition Height="*"/> 
                        <RowDefinition Height="60"/> 
                    </Grid.RowDefinitions> 
                         
                <ContentPresenter Grid.Row="0" Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"/> 
                         
                    <Button Grid.Row="1" Content="ola"/> 
                     
                </Grid> 
            </DataTemplate> 
            
 
            <Style TargetType="local:Dialog"
                <Setter Property="ContentTemplate" Value="{StaticResource ChangedTemplate}"/> 
        </Style> 
        </ResourceDictionary> 
         
         
    </telerik:RadWindow.Resources> 
The code above is the just with the content with one button (marking the area of the footer).



Then in mainpage i call this dialog and add one button to the content:
<my3:Dialog x:Name="xdialog" BorderBackground="#FF121010" 
                    Background="Lime" BorderBrush="Blue" BorderThickness="1" 
                    WindowStartupLocation="CenterScreen" Opacity="10" Header="This is popup" 
                DialogResult="True"
            <StackPanel> 
                 <TelerikControl:RadButton x:Name="buttontoDisable" Height="50" Width="50" Content="TryIt"/> 
            </StackPanel> 
        </my3:Dialog> 

 The strange thing (at least for me!!) is when in the code-behind of the mainWindow (c#) if i try to call the "buttontoDisable" (say for example disable it), gives to me a "System.NullReferenceException".

What i'm doing wrong here?

4 Answers, 1 is accepted

Sort by
0
CarlosLima
Top achievements
Rank 1
answered on 08 Jul 2010, 10:28 AM
I have the same problem here.

Can anyone have solution?

Thanks
0
Accepted
George
Telerik team
answered on 12 Jul 2010, 03:03 PM
Hello David,

Thank you for contacting us!

Defining a window in the xaml (i.e. not as a root tag) is not a good approach and we don't support it because it might lead to unexpected behavior. The x:names of the buttons you want to find are defined in different namecope - that's why they couldn't be resolved in the InitializeComponent method. You can get them from the namescope of your custom window. You can use FindName method of the window, for example:

this.xdialog.FindName("buttonOfContainer") as Button;

You can work around this approach with initializing the objects you use in your custom dialog, so you can call them through your custom window, for example.
If you want your footer to participate in the namescope of your custom window, you should edit the ControlTemplate of the window and add a new ControlPresenter for the footer.

I hope this information helps. I will be glad to assist you further.
  
Sincerely yours,
George
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
0
Artur
Top achievements
Rank 1
answered on 13 Jul 2010, 05:02 PM
Can you give to me some example how to get the footer participate in the namecope?

Thank you
0
Accepted
George
Telerik team
answered on 14 Jul 2010, 04:20 PM
Hello Artur,

Thank you for getting back to me.

First, you need to create two dependency properties Footer and FooterTemplate in your custom window control, same as Content and ContentTemplate properties. Then, apply the attached theme to your control.
 
I hope this helps. I will be glad to assist you further.

Sincerely yours,
George
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
Asked by
Artur
Top achievements
Rank 1
Answers by
CarlosLima
Top achievements
Rank 1
George
Telerik team
Artur
Top achievements
Rank 1
Share this question
or