private string txtb1;
public string TextBox1 {
get { return txtb1; }
set
{
txtb1 = value;
OnPropertyChanged("IndicatedPath");
}
}
public ICommand BrowseFolder
{
get { return new RelayCommand((obj) =>
{
Winforms.FolderBrowserDialog fbd = new Winforms.FolderBrowserDialog();
fbd.RootFolder = Environment.SpecialFolder.DesktopDirectory;
fbd.Description = "Select Folder";
fbd.ShowNewFolderButton = false;
if (fbd.ShowDialog() == Winforms.DialogResult.OK)
{
TextBox1 = fbd.SelectedPath;
}
}); }
}
<TextBox x:Name="TextBox" HorizontalAlignment="Left" Margin="88,88,0,0" Text="{Binding TextBox1}" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Height="19" />
<Button x:Name="button" Content="Folder 1" HorizontalAlignment="Left" Margin="10,87,0,0" VerticalAlignment="Top" Width="57" Command="{Binding BrowseFolder}" CommandParameter="0"/>
<Button x:Name="button_Copy" Content="Folder 2" HorizontalAlignment="Left" Margin="683,87,0,0" VerticalAlignment="Top" Height="19" Width="66" Command="{Binding BrowseFolder}" CommandParameter="1"/>
get { return new RelayCommand((obj) =>
{
if(obj is int ival)
{
Winforms.FolderBrowserDialog fbd = new Winforms.FolderBrowserDialog();
fbd.RootFolder = Environment.SpecialFolder.DesktopDirectory;
fbd.Description = "Select Folder";
fbd.ShowNewFolderButton = false;
if (fbd.ShowDialog() == Winforms.DialogResult.OK)
{
if(ivalue == 0) TextBox1 = fbd.SelectedPath;
else if (ivalue ==1) TextBox2 = fbd.SelectedPath;
}
}
}); }
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
this.execute = execute;
this.canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return canExecute == null || canExecute(parameter);
}
public void Execute(object parameter)
{
execute(parameter);
}
public void Browse(object obj)
{
if (obj is string ival)
{
Winforms.FolderBrowserDialog fbd = new Winforms.FolderBrowserDialog
{
RootFolder = Environment.SpecialFolder.DesktopDirectory,
Description = "Select Folder",
ShowNewFolderButton = false
};
if (fbd.ShowDialog() == Winforms.DialogResult.OK)
{
if (ival == "0")
{
TextBox1 = fbd.SelectedPath;
TxtBlock = string.Join("\n", Directory.GetFiles(fbd.SelectedPath)
.Select(file => Path.GetFileName(file)));
} else if (ival == "1")
{
TextBox2 = fbd.SelectedPath;
TxtBlock2 = string.Join("\n", Directory.GetFiles(fbd.SelectedPath)
.Select(file => Path.GetFileName(file)));
}
}
}
}
private string textBox1;
public string TextBox1 {
get => textBox1;
set {
textBox1 = value;
OnPropertyChanged(nameof(TextBox1));
}
}
private string textBox2;
public string TextBox2 {
get => textBox2;
set {
textBox2 = value;
OnPropertyChanged(nameof(TextBox2));
}
}
private string txtBlock;
public string TxtBlock {
get => txtBlock;
set {
txtBlock = value;
OnPropertyChanged(nameof(TxtBlock));
}
}
private string txtBlock2;
public string TxtBlock2 {
get => txtBlock2;
set {
txtBlock2 = value;
OnPropertyChanged(nameof(TxtBlock2));
}
}
var files = Directory.GetFiles(fbd.SelectedPath).Select(file => Path.GetFileName(file));
if (ival == "0")
{
TextBox1 = fbd.SelectedPath;
TxtBlock = string.Join("\n", files);
}
else if (ival == "1")
{
TextBox2 = fbd.SelectedPath;
TxtBlock2 = string.Join("\n", files);
}