|
hello
I say first that this code works with windowsFormApplication, but no work with wpf, help me please
namespace WpfApplication22
{
public partial class App : Application
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
private const int APPCOMMAND_XXX = 0x80000;
private void MetodoMute(object sender, EventArgs e)
{
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_xxx);
}
}
}
when I use:
private void button4_Click(object sender, RoutedEventArgs e)
{
App x = new App();
x.MetodoMute(new WindowInteropHelper(this).Handle);
}
not works, It's launch exception:
"Eccezione non gestita di tipo 'System.InvalidOperationException' in PresentationFramework.dll
Informazioni aggiuntive: Impossibile creare più di un'istanza System.Windows.Application nello stesso AppDomain."
how do I call a method written in App.xaml.cs from another window?
|
|
|
|
|
App is a special class - it's the entry point for your WPF application. In other words, it's the class you use to create your application - the good news is that this class is available throughout the code base, so all you need to do is use App.MetadoMute (also, you need to use a method call that matches your signature).
|
|
|
|
|
I can not use App.MyMetod(...) in the file MainWindow.xaml.cs
don't work
how do I call a method written in the class App from the class MainWindow?
private void button4_Click(object sender, RoutedEventArgs e)
{
App.MetodoMute(new WindowInteropHelper(this).Handle);
}
|
|
|
|
|
You can use Application as your class to call MetodoMute. You simply cast it to App.
|
|
|
|