.xamlにテキストボックスとボタンがあります。ボタンをクリックすると、ファイルダイアログを開くことができ、ファイルを選択することもできます。
MainWindow.Xaml:
<TextBox Height="93" IsReadOnly="True" Text="{Binding Path=ReadMessage, Mode=TwoWay}" Name="MessageRead" />
<Button Content="Load" Name="I2CLoadBtn" Command={Binding Path = LoadContentCommand />
私のViewModelクラス:
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";
}
基本的に必要なのは、ファイルを選択したら、ファイルの内容をテキストボックスに保存する必要があるということです。たとえば、ロードする.txtファイルがある場合、ロード時にコンテンツをテキストボックス内に配置する必要があります。
助けてください!!!