views:

21

answers:

1

Hi,

I've XAML that looks a bit like this:

<UserControl x:Class="MyNamespace.MyClass"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:local="clr-namespace:MyNamespace"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="500">

<UserControl.Resources>
    <local:MyViewModel x:Key="ViewModel"/>
</UserControl.Resources>

<UserControl.DataContext>
    <Binding Source="{StaticResource ViewModel}"/>
</UserControl.DataContext>

    <DataGrid Name="_myGrid" AutoGenerateColumns="False" 
   ItemsSource="{Binding Path=MyDataTable}">        
   <DataGrid.Columns>
            <DataGridTemplateColumn Header="Name">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock Text="{Binding Path=name}" />
                            <TextBlock Text="{Binding 
                                Source={StaticResource ViewModel}, Path=IsValidName}"/>
                        </StackPanel>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <Grid FocusManager.FocusedElement="{Binding ElementName=NameTextBox}">
                            <TextBox Name="NameTextBox" Text="{Binding Path=name}" />
                        </Grid>
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>

        </DataGrid.Columns>
    </DataGrid>

As you can probably see above, my DataGrid binds to a data table as its ItemsSource. I typically bind to columns in the data table view, such as 'name'. In some cases, I bind to my view model, rather than a DataRowView. That can be seen in the 2nd TextBlock above, where I bind to the view model's IsValidName property. My question is, how can I pass information from my XAML back to my binding source, in this case my view model? I'd like to pass the rowIndex, DataRowView object, name, or something similar so that the IsValidName property on the view model would have context as to which row is being validated.

Thanks,

Notre

A: 

Looks like you want to call your IsValidName Property like a Method passing Parameters as to which row is being validated.

if you have control over each row's Type, implement the IsValidName Property there, completely avoiding the StaticResource Binding!

redoced
Each row is a DataRowView, as it is a row in a data table's view. So, I don't think I can add my IsValidName property there (can I?)
Notre