I have a textbox and a button in my .xaml. When i click the button i am able to open a filedialog and able to select the file as well.
MainWindow.Xaml:
<TextBox Height="93" IsReadOnly="True" Text="{Binding Path=ReadMessage, Mode=TwoWay}" Name="MessageRead" />
<Button Content="Load" Name="I2CLoadBtn" Command={Binding Path = LoadContentCommand />
My ViewModel Class:
public static RelayCommand LoadContentCommand { get; set; }
private string _ReadMessage;
public string ReadMessage
{
get { return __ReadMessage; }
set
{
__ReadMessage= value;
NotifyPropertyChanged("ReadMessage");
}
}
private void RegisterCommands()
{
LoadContentCommand = new RelayCommand(param => this.ExecuteOpenFileDialog());
}
private void ExecuteOpenFileDialog()
{
var dialog = new OpenFileDialog { InitialDirectory = _defaultPath };
dialog.ShowDialog();
dialog.DefaultExt = ".bin";
dialog.Filter = "Bin Files (*.bin)|*.bin";
}
What i basically want is, once the file is selected, the contents of the file must be saved into the textbox. E.g. If I have a .txt file to be loaded, on loading the contents must get placed inside the textbox.
Please help!!!
This is how you get the selected path: