Null exception

5 posts, 2 answers
  1. Artur
    Artur avatar
    19 posts
    Member since:
    Jul 2010

    Posted 07 Jul 2010 Link to this post

    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?
  2. CarlosLima
    CarlosLima avatar
    47 posts
    Member since:
    May 2010

    Posted 08 Jul 2010 Link to this post

    I have the same problem here.

    Can anyone have solution?

    Thanks
  3. DevCraft banner
  4. Answer
    George
    Admin
    George avatar
    1332 posts

    Posted 12 Jul 2010 Link to this post

    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
  5. Artur
    Artur avatar
    19 posts
    Member since:
    Jul 2010

    Posted 13 Jul 2010 Link to this post

    Can you give to me some example how to get the footer participate in the namecope?

    Thank you
  6. Answer
    George
    Admin
    George avatar
    1332 posts

    Posted 14 Jul 2010 Link to this post

    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
Back to Top
DevCraft banner