Explanation: I have to get FolderBrowserDialog Box once I click the browse button. And In FolderBrowserDialog Box,if I select any folder and click ok,that particular folderpath along with foldername should be shown in the textbox which is beside the browse button....But I didn't get anything once I click Browse button. Please check my code and correct me...
View.xaml :
<Window.... xmlns:VM="clr-namespace:myproject.myViewModel"
... >
<Window.DataContext><VM:myViewModel/>
<Grid>...
<TextBlock Text="Folder to save files" VerticalAlignment="Center" />
<TextBox Text="{Binding Path=FoldernameWithPath , UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Height="26" IsReadOnly="True" VerticalContentAlignment="Center" Width="150" />
<Button Content="Browse" Height="26" VerticalAlignment="Bottom" MinWidth="45" Command="{Binding OpenFolderCommand}" />
</Grid>
</window>
ViewModel.cs
public ICommand OpenFolderCommand
{
get => new RelayCommand(a => this.OpenFolder(), p => CanOpenFolder());
}
private string _foldernameWithPath;
public string FoldernameWithPath
{
get { return _foldernameWithPath; }
set
{
if (value == _foldernameWithPath)
{
return;
}
else
{
_foldernameWithPath = value;
OnPropertyChanged("FoldernameWithPath");
}
}
}
public bool CanOpenFolder()
{
return true;
}
private void OpenFolder()
{
FolderBrowserDialog openFolderDialog = new FolderBrowserDialog();
if (openFolderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK && OpenFolderCommand.CanExecute(openFolderDialog.SelectedPath))
{
OpenFolderCommand.Execute(openFolderDialog.SelectedPath);
FoldernameWithPath = openFolderDialog.SelectedPath;
}
}