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:RadGridView Grid.Row="0" Grid.Column="0" x:Name="workGridView" [...] ItemsSource="{Binding [...]}" > <telerik:RadGridView.Columns> [...] </telerik:RadGridView.Columns></telerik:RadGridView><Button Grid.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:
private DelegateCommand addWorkCommand_ = null;public DelegateCommand addWorkCommand{ get { if (this.addWorkCommand_ == null) { this.addWorkCommand_ = new DelegateCommand( o => addWork(o) ); } return this.addWorkCommand_; }}private void addWork(object o){ 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 is valid only on elements that have this template applied.I don't understand. I'm getting the template from the form. How can it not be applied?