在 WPF 应用程序中,通过使用 c#,我希望用户能够将他们的数据导入网格视图。那么我需要一个浏览按钮还是什么?
如果是,我该怎么做?
以下代码可帮助您显示浏览按钮
<TextBox Height="32" HorizontalAlignment="Left" Margin="6,10,0,0" Name="FileNameTextBox"
VerticalAlignment="Top" Width="393" />
<Button Content="Browse" Height="32" HorizontalAlignment="Left" Margin="405,10,0,0"
Name="button1" VerticalAlignment="Top" Width="88" Click="button1_Click" />
// Create OpenFileDialog
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;
FileNameTextBox.Text = filename;
}