0

We have WPF application, In which we use DataGrid on one form. Our requirement is that In One column Of that Datagrid there will be onr Button, After clicking it will ask for browse file, & it will take path of that file. Afterward that path will set to textBlock which replaced that same button. So What need to be done? Currently we are able to get path, but how to show TextBlock after selecting path from Browsing.

    <toolkit:DataGridTemplateColumn Header="Attachment Copy Of Invoice" Width="180" >
                <toolkit:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock x:Name="Attach" Uid="Ata" Text="{Binding   Path=Attachment, UpdateSourceTrigger=PropertyChanged}" />
                    </DataTemplate>
                </toolkit:DataGridTemplateColumn.CellTemplate>
                <toolkit:DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <Button Name="Click" Click="Click_Click"  ></Button>
                    </DataTemplate>
                </toolkit:DataGridTemplateColumn.CellEditingTemplate>
            </toolkit:DataGridTemplateColumn>
Constant Learner
  • 525
  • 4
  • 13
  • 30

1 Answers1

0

First of all you should not handle the Button_Click in that way. You should place an ICommand somewhere in your ViewModel and bind the Button to that Command.

Second, all you need to do to show the new text in the textblock is to update the Attachment property you're binding it to:

<toolkit:DataGridTemplateColumn.CellEditingTemplate>
    <DataTemplate>
        <Button Command="{Binding MyCommand}"/>
    </DataTemplate>
</toolkit:DataGridTemplateColumn.CellEditingTemplate>

ViewModel:

public class MyViewModel
{
    public DelegateCommand MyCommand {get;set;}

    public MyViewModel()
    {
        MyCommand = new DelegateCommand(ExecuteMyCommand);
    }

    private void ExecuteMyCommand(object parameter)
    {
        Attachment = WhateverYouWantToPlacethere;
    }
}
Federico Berasategui
  • 43,562
  • 11
  • 100
  • 154