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

ItemSource Binding happens twice

2 Answers 205 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jaco De Villiers
Top achievements
Rank 2
Jaco De Villiers asked on 29 Dec 2010, 08:32 AM
Hi,

I am using the RadGridView in an MVVM project.  The ViewModel has a property ObservableCollection<T> to which the ItemSource property is bound.  When a I  place a break point in the ViewModel property get, then it is accessed twice.  Am I doing something wrong?  The XAML is below.  Also, what is the best practice when loading data using a pager and ensuring only page size is loaded from the database and not all records (e.g. Take(20));

Regards
Jaco

<Window x:Class="DBAppBestPractice.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:Examples="clr-namespace:DBAppBestPractice"
                xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
                x:Name="root"
                 DataContext="{Binding Main, Source={StaticResource Locator}}"
                >
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Skins/MainSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
     
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
 
        <Border  Grid.RowSpan="2" />
 
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,5,0,0">
            <telerik:RadButton Width="150" Content="Delete selected rows" Margin="0,0,5,0"
                                 Command="telerikGrid:RadGridViewCommands.Delete" CommandTarget="{Binding ElementName=RadGridView1}"  />
            <telerik:RadButton Width="150" Content="Add new row" Margin="0,0,5,0"
                                 Command="telerikGrid:RadGridViewCommands.BeginInsert" CommandTarget="{Binding ElementName=RadGridView1}"  />
            <telerik:RadButton Width="150" Content="Save insert/edit" Margin="0,0,5,0"
                                 Command="telerikGrid:RadGridViewCommands.CommitEdit" CommandTarget="{Binding ElementName=RadGridView1}"  />
            <telerik:RadButton Width="150" Content="Cancel insert/edit"
                                 Command="telerikGrid:RadGridViewCommands.CancelRowEdit" CommandTarget="{Binding ElementName=RadGridView1}"  />
        </StackPanel>
        <telerik:RadGridView x:Name="RadGridView1"
                                                 ItemsSource="{Binding LoadedSuppliers}"
                                                 SelectionMode="Extended"
                                                 AutoGenerateColumns="False"
                                                 Margin="0,5,0,0"
                                                 Grid.Row="1"
                                                 ActionOnLostFocus="None" RowEditEnded="RadGridView1_RowEditEnded" Deleted="RadGridView1_Deleted">
            <telerik:RadGridView.Columns>
                <telerik:GridViewColumn>
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadButton Content="Delete" Command="telerikGrid:RadGridViewCommands.Delete" CommandParameter="{Binding}" />
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Id}" Header="Id" IsReadOnly="True" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Name" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}" Header="Description" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</Window>

2 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 29 Dec 2010, 10:35 AM
Hello Jaco De Villiers,

I could not reproduce the problem with the double invokes of the getter. Find attached a sample project.

You can also check the Unbound Mode of RadDataPager.

Greetings,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Jaco De Villiers
Top achievements
Rank 2
answered on 11 Jan 2011, 08:51 AM
Hi, thank you for the sample project.  I will post my sample if you don't mind
Regards
Jaco
Tags
GridView
Asked by
Jaco De Villiers
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Jaco De Villiers
Top achievements
Rank 2
Share this question
or