Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 78072

Error: “This operation is valid only on elements that have this template applied”

$
0
0

I have a C# WPF application that contains a user control:

<UserControl
        x:Name="payrollEntryControl"
        x:Class="MyNamespace.PayrollEntryControl"
        [...]
        >
    [...]
</UserControl>

Within the user control, I have a Telerik RadDataForm:

<telerik:RadDataForm
        x:Name="payrollAddForm"
        CurrentItem="[...]"
        EditTemplate="{StaticResource myEditTemplate}"
        />

 

The template contains a Telerik RadGridView and a Button:

<telerik:RadGridViewGrid.Row="0"Grid.Column="0"
        x:Name="workGridView"
        [...]
        ItemsSource="{Binding [...]}"
        >
    <telerik:RadGridView.Columns>
        [...]
    </telerik:RadGridView.Columns>
</telerik:RadGridView>
<ButtonGrid.Row="1"Grid.Column="0"
        Command="{Binding addWorkCommand, ElementName=payrollEntryControl}"
        >
    Add
</Button>

I want the command to do is call BeginInsert() on workGridView. But I can't seem to get access to workGridView.

My command, so far:

privateDelegateCommand addWorkCommand_ = null;
publicDelegateCommand addWorkCommand
{
    get
    {
        if(this.addWorkCommand_ == null)
        {
            this.addWorkCommand_ = newDelegateCommand(
                o => addWork(o)
            );
        }
 
        returnthis.addWorkCommand_;
    }
}
 
privatevoidaddWork(objecto)
{
    var addForm = this.payrollAddForm;
    var editTemplate = addForm.EditTemplate;
    var workGrid = editTemplate.FindName("workGridView", addForm);
}

 

My problem? When I make the call to editTemplate.FindName(), I get an exception:

This operation isvalid only on elements that have thistemplate applied.

I don't understand. I'm getting the template from the form. How can it not be applied?

Viewing all articles
Browse latest Browse all 78072

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>