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>
share|improve this question

1 Answer

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;
    }
}
share|improve this answer
Will you please tell me , What is ViewModel in this case? How it will work? I am a Newbie in WPF . Thanks. – Constant Learner Feb 11 at 14:56
This answer might help you – HighCore Feb 11 at 15:00
I am not using MVVM so will you please tell me any alternative on this. – Constant Learner Feb 12 at 4:48
There is no alternative. There's basically 2 ways of doing things in WPF. One is the simplicity and beauty of MVVM, the other one is a bunch of horrible hacks and gargantuan amounts of unnecesary code. It's your choice. – HighCore Feb 12 at 4:59

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.