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>
4

1 回答 1

0

首先,您不应该以这种方式处理 Button_Click。您应该ICommand在 ViewModel 中放置一个并将 Button 绑定到该命令。

其次,在文本块中显示新文本所需要做的就是更新Attachment 您将其绑定到的属性:

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

视图模型:

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

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

    private void ExecuteMyCommand(object parameter)
    {
        Attachment = WhateverYouWantToPlacethere;
    }
}
于 2013-02-11T14:48:50.847 回答