0
私はViewModel
にView
からボタンにアクセスしようとしていますが、私はエラーが出るように私は何かが欠けています:アクセスボタン
Severity Code Description Project File Line Suppression State
Error CS1061 'MainWindow' does not contain a definition for 'Loadfile' and no extension method 'Loadfile' accepting a first argument of type 'MainWindow' could be found (are you missing a using directive or an assembly reference?) Uml-Creator C:\Users\HH\Source\Repos\UMLEditor\Uml-Creator\Uml-Creator\View\MainWindow.xaml 54 Active
ボタンの目的を開くことですがOpenFileDialog
。
class Load
{
private void Loadfile(object sender, EventArgs e)
{
OpenFileDialog loadfile = new OpenFileDialog();
if (loadfile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// File.Text = File.ReadAllText(loadfile.FileName);
}
}
}
とビュー:私のViewModel
で私はこのようなクリックを扱う
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
EDIT:
<Button x:Name="openButton" ToolTip="Open project" Click="Load_Click">
<Image Source="pack://application:,,,/Images\Open.png" Stretch="UniformToFill" Height="17"></Image>
</Button>
「xaml」はどのように定義されていますか? –
MVVMの概念に違反しています。あなたのビューモデルはあなたの意見について何も知ってはいけません。 viewmodelで動作させたい場合は、ICommand – Alex
を使うべきです。ViewのDataContextが 'Load'クラスに設定されていないようです。 – Rabban