0

ここに画像の説明を入力1 つのフォームで DataGrid を使用する WPF アプリケーションがあります。その DATAGRID で複数の DataTemplateColumn を使用しました。「BROWSE」ボタンを想定して、1 つの列に 1 つのボタンを配置する必要があります。EDITモードでクリックするとファイルダイアログが開き、ファイルを選択すると、そのファイルのパスがそのDATAGRID列に保存される必要があります。これを達成する方法は、編集モードでBRowseボタンと通常モードでそのファイルのパスです。

<toolkit:DataGridTemplateColumn Header="Attachment Copy Of Invoice" Width="180" >
                <toolkit:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>

                        <TextBlock x:Name="Attach"  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>

コード:

 private void Click_Click(object sender, RoutedEventArgs e)
    {
        Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

        // Set filter for file extension and default file extension

        dlg.DefaultExt = ".txt";
        dlg.Filter = "Text documents (.txt)|*.txt";

        // Display OpenFileDialog by calling ShowDialog method
        Nullable<bool> result = dlg.ShowDialog();

        // Get the selected file name and display in a TextBox
        if (result == true)
        {

            // Open document

            string filename = dlg.FileName;


        }


    }

ファイル名、つまり同じ TextBlock へのパスを保存する必要があります。

4

1 に答える 1

0
private void Click_Click(object sender, RoutedEventArgs e) {
   var dlg = new Microsoft.Win32.OpenFileDialog();

    // Set filter for file extension and default file extension

    dlg.DefaultExt = ".txt";
    dlg.Filter = "Text documents (.txt)|*.txt";

    // Display OpenFileDialog by calling ShowDialog method
    Nullable<bool> result = dlg.ShowDialog();

    // Get the selected file name and display in a TextBox
    if (result == true) {
        // Open document
        string filename = dlg.FileName;
        var yourType = ((FrameworkElement)sender).DataContext as YourType;
        yourType .Attachment= filename;
    }
 }
于 2013-10-14T05:50:05.953 に答える