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

[Solved] How do you use binding with a DataForm in a DetailsPresenter

1 Answer 212 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris Jones
Top achievements
Rank 1
Chris Jones asked on 30 Sep 2009, 09:10 PM
Hello,

The issue I am running into is trying to figure out what to use as the binding statement on the CurrentItem property of a DataForm that is used in a DetailsPresenter.  The dataform is declared in a different xaml file than the radgridview.  Any help would be appreciated.

MainPage.xaml
<UserControl x:Class="ICS.SmartConsole.Mobile.Labor.SilverlightPrototypes.TelerikGrid.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:e="clr-namespace:ICS.Labor.EntityModel" 
    xmlns:web="clr-namespace:ICS.SmartConsole.Mobile.Labor.SilverlightPrototypes.TelerikGrid.Web" 
    xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Ria.Controls" 
    xmlns:riaData="clr-namespace:System.Windows.Data;assembly=System.Windows.Ria.Controls" 
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
    xmlns:grid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
    xmlns:gridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView" 
    xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
    xmlns:dataFormToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit" 
    xmlns:local="clr-namespace:ICS.SmartConsole.Mobile.Labor.SilverlightPrototypes.TelerikGrid" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">  
    <Grid x:Name="LayoutRoot">  
        <Grid.Resources> 
            <!--<DataTemplate x:Key="GridViewRowTemplate">  
                <TextBlock Text="Row details here!" /> 
            </DataTemplate>--> 
            <DataTemplate x:Key="GridViewRowTemplate">  
                <local:EmployeeEdit /> 
            </DataTemplate> 
        </Grid.Resources> 
 
        <Grid.RowDefinitions> 
            <RowDefinition Height="Auto" /> 
            <RowDefinition /> 
            <RowDefinition Height="Auto" /> 
            <RowDefinition Height="Auto" /> 
        </Grid.RowDefinitions> 
 
        <riaControls:DomainDataSource x:Name="RiaDomainDataSource" 
                                      AutoLoad="True" 
                                      QueryName="GetEmployee" 
                                      LoadSize="20" 
                                      LoadingData="RiaDomainDataSource_LoadingData" 
                                      LoadedData="RiaDomainDataSource_LoadedData">  
            <riaControls:DomainDataSource.DomainContext> 
                <web:DomainService1/> 
            </riaControls:DomainDataSource.DomainContext> 
            <riaControls:DomainDataSource.FilterDescriptors> 
                <riaData:FilterDescriptorCollection LogicalOperator="Or" /> 
            </riaControls:DomainDataSource.FilterDescriptors> 
        </riaControls:DomainDataSource> 
 
        <telerikNavigation:RadToolBar x:Name="Toolbar" 
                                      Grid.Row="0">  
            <TextBlock Text="RECORDS:" 
                       Margin="0,0,0,0"/>  
            <Button Content="Search" 
                    Margin="5,0,0,0" 
                    Click="Search_Click">  
                  
            </Button> 
            <Button Content="Insert" 
                    Margin="5,0,0,0">  
                  
            </Button> 
            <telerikNavigation:RadToolBarSeparator/> 
        </telerikNavigation:RadToolBar> 
          
        <grid:RadGridView x:Name="GridView" 
                          Grid.Row="1" 
                          AutoGenerateColumns="False" 
                          ColumnsWidthMode="Fill" 
                          RowDetailsVisibilityMode="Collapsed"    
                          RowDetailsTemplate="{StaticResource GridViewRowTemplate}" 
                          RowIndicatorVisibility="Collapsed" 
                          CanUserInsertRows="False" 
                          ItemsSource="{Binding Data, ElementName=RiaDomainDataSource}" 
                          Filtering="GridView_Filtering" 
                          IsReadOnly="True">  
            <grid:RadGridView.Columns> 
                <grid:GridViewDataColumn Header="Last Name" 
                                         DataMemberBinding="{Binding LastName}"/>  
                <grid:GridViewDataColumn Header="First Name" 
                                         DataMemberBinding="{Binding FirstName}" /> 
                <grid:GridViewDataColumn Header="Enabled" 
                                         DataMemberBinding="{Binding Enabled}">  
                    <grid:GridViewDataColumn.CellTemplate> 
                        <DataTemplate> 
                            <CheckBox IsChecked="{Binding Enabled}" IsEnabled="False" /> 
                        </DataTemplate> 
                    </grid:GridViewDataColumn.CellTemplate> 
                    <!--<grid:GridViewDataColumn.CellEditTemplate> 
                        <DataTemplate> 
                            <CheckBox IsChecked="{Binding Enabled, Mode=TwoWay}" /> 
                        </DataTemplate> 
                    </grid:GridViewDataColumn.CellEditTemplate>--> 
                </grid:GridViewDataColumn> 
 
            </grid:RadGridView.Columns> 
        </grid:RadGridView> 
        <Border x:Name="GridExternalDetailBorder"   
                Grid.Row="2"   
                Visibility="Visible">  
            <gridView:DetailsPresenter x:Name="GridExternalDetailPresenter"   
                                       Visibility="Visible"   
                                       DetailsProvider="{Binding RowDetailsProvider, Mode=TwoWay, ElementName=GridView}" 
                                       > 
 
            </gridView:DetailsPresenter> 
        </Border> 
        <data:DataPager x:Name="GridViewPager"   
                        Grid.Row="3"   
                        PageSize="20"   
                        Source="{Binding Data, ElementName=RiaDomainDataSource}">  
        </data:DataPager> 
    </Grid> 
</UserControl> 

Employee.xaml
<UserControl   x:Class="ICS.SmartConsole.Mobile.Labor.SilverlightPrototypes.TelerikGrid.EmployeeEdit" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:dataFormToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit" 
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">  
 
    <Grid x:Name="EmployeeEditGrid">  
        <StackPanel> 
            <TextBlock Text="First Name" 
                   FontWeight="Bold" 
                   Height="40" /> 
            <TextBox Text="{Binding FirstName, Mode=TwoWay}" 
                 Margin="12,0,0,0" 
                 Height="40"/>  
 
            <dataFormToolkit:DataForm x:Name="EmployeeDataForm" 
                                  Height="300" 
                                  CurrentItem="{Binding CurrentItem, ElementName=GridView}">  <!-- THIS IS WHERE THE ISSUE IS  -->
            </dataFormToolkit:DataForm> 
        </StackPanel> 
    </Grid> 
</UserControl> 
 

I just need some guidance as to what to use as the binding declaration.

Thanks,

Chris

1 Answer, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 02 Oct 2009, 10:19 AM
Hello Chris,

Unfortunately Silverlight framework did not provide the functionality you need.

However what you can do is something called attached binding. You can create an attached property (attached behavior) and attach it to your data form. When this property is attached to the data form you should subscribe to its Loaded event. In the loaded handler you should start looking up in the VisualTree for the first RadGridView control (using some helper extension methods like ParentOfType<RadGridView>()). When you find it you can data bind the form's CurrentItem property to the CurrentItem of the RadGridView.

Hope this helps.

Kind regards,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Chris Jones
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Share this question
or