ViewModel Binding not Working inside the datagrid.

Nov 12, 2009 at 6:38 PM

Hi all, i dont know what is the problem but i can't seem to be able to bind anything external inside my datagrid.

 

Im able to bind some properties defined in the items of my itemssourcer.

 

here's an example:

 ->In the following example please note that the textbox outside the datagrid is working fine, but the Textboxes inside the header sections are not working.

Also the the LockableDatagrid is just a extention of the original datagrid (added some lockable row functionalities) and the problem is present with the normal datagrid.

So what am i doing wrong here?

<UserControl x:Class="Views.OrganizationView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="clr-namespace:UILayer.ViewModels"
             xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
             xmlns:d="clr-namespace:UILayer.DataGridSample_LockingRowInEditMode"
             xmlns:myCtrl="clr-namespace:UILayer"
             xmlns:Converters="clr-namespace:UILayer.Converters">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\Form Components\ControlDictionary.xaml"/>
                <ResourceDictionary Source="..\ColorsStyles.xaml" />
            </ResourceDictionary.MergedDictionaries>            
        </ResourceDictionary>
    </UserControl.Resources>
    
    <UserControl.DataContext>
        <vm:OrganizationViewModel x:Name="OrgVM"/>
    </UserControl.DataContext>

    <StackPanel>
        <TextBox Text="{Binding ElementName=OrgVM, Path=Filter_OrgID, UpdateSourceTrigger=PropertyChanged}"/>


                    <d:LockableDataGrid   
                         AutoGenerateColumns="False"                                       
                         SelectionUnit="FullRow"
                         ItemsSource="{Binding DisplayedCollection.View}"
                         SelectedItem="{Binding CurrentOrganization}" 
                         IsSynchronizedWithCurrentItem="True" 
                         SelectedValuePath="OrganizationID"
                         RowStyle="{StaticResource defaultRowStyle}"
                         CellStyle="{StaticResource defaultCellStyle}"
                         CanUserAddRows="False"
                         SelectionMode="Single"
                         CanUserDeleteRows="False"
                         IsReadOnly="True"
                         RowBackground="White"
                         AlternatingRowBackground="LightBlue"
                         AlternationCount="2"
                         Margin="0,0,5,0">
                        <d:LockableDataGrid.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding LockedOnEdit}" Value="True" >
                                        <Setter Property="d:LockableDataGrid.IsEnabled" Value="False"/>
                                        <Setter Property="d:LockableDataGrid.LockOnRow" Value="True"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding LockedOnEdit}" Value="False" >
                                        <Setter Property="d:LockableDataGrid.IsEnabled" Value="True"/>
                                        <Setter Property="d:LockableDataGrid.LockOnRow" Value="False"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </d:LockableDataGrid.Style>

                        <d:LockableDataGrid.Columns>
                            <dg:DataGridTextColumn Binding="{Binding Path=OrganizationID}">
                                <dg:DataGridTextColumn.Header>
                                    <StackPanel >
                                        <TextBlock Text="Organization ID"/>
                                        <TextBox Text="{Binding ElementName=OrgVM, Path=Filter_OrgID, UpdateSourceTrigger=PropertyChanged}"/>
                                    </StackPanel>
                                </dg:DataGridTextColumn.Header>
                            </dg:DataGridTextColumn>

                            <dg:DataGridTextColumn x:Name="colOrganization" Binding="{Binding Path=Name}" SortDirection="Ascending" SortMemberPath="Name">
                                <dg:DataGridTextColumn.Header>
                                    <StackPanel >
                                        <TextBlock Text="Organization Name"/>
                                        <TextBox Text="{Binding ElementName=OrgVM, Path=Filter_OrgName, UpdateSourceTrigger=PropertyChanged}"/>
                                    </StackPanel>
                                </dg:DataGridTextColumn.Header>
                            </dg:DataGridTextColumn>

                            <dg:DataGridTextColumn x:Name="colParentOrganization"  CanUserSort="True" Binding="{Binding Path=Organization2.Name}" SortMemberPath="Organization.Name">
                                <dg:DataGridTextColumn.Header>
                                    <StackPanel >
                                        <TextBlock Text="Parent Organization"/>
                                        <TextBox  Text="{Binding ElementName=OrgVM, Path=Filter_ParentOrgName, UpdateSourceTrigger=PropertyChanged}" />
                                    </StackPanel>
                                </dg:DataGridTextColumn.Header>
                            </dg:DataGridTextColumn>


                        </d:LockableDataGrid.Columns>
                    </d:LockableDataGrid>
	</StackPanel>
</UserControl>
Nov 13, 2009 at 3:45 PM

Any clue?