Required — when a button is pressed, call a method

public string Picha_SaveFile() { saveFileDialog.DefaultExt = "png"; saveFileDialog.Filter = "Image files (*.png;*jpg;*gif)|*.png; *jpg; *gif;|All files (*.*)|*.*"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { return saveFileDialog.FileName; } return ""; } 

Closed due to the fact that the essence of the question is not clear to the participants iksuy , Igor , αλεχολυτ , Sasha Omelchenko , Kromster 23 Mar '17 at 12:36 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

1 answer 1

Do you use MVVM pattern? If yes, then:

 private ICommand _someCommand; public ICommand SomeCommand { get { if (_someCommand== null) _ledChangeCommand = new RelayCommand<string>(Picha_SaveFile); return _someCommand; } } 

In the XAML markup:

 <Button x:Name="button" ... Command="{Binding SomeCommand}" CommandParameter="SomeParamater" /> 

If you do not use the MVVM pattern , then everything is much easier. Create a button on the form, give it a specific name and the following code:

 btn.Click += btn1_Click; private void btn1_Click(object sender, RoutedEventArgs e) { // Picha_SaveFile(); // }