This is the error I get: : 'Failed to create a 'Click' from the text 'OkClick'.' Line number '5' and line position '27'.
The cs file and xaml file cannot be created on the same IDE, so I am calling it like this.
private Button okButton;
FileStream fs1 = new FileStream(System.IO.Path.Combine(path, FileMode.Open);
System.Windows.Application.Current.Dispatcher.Invoke((Action)delegate{
window = new Window();
Page page = new Page();
page = (Page)XamlReader.Load(fs1);
okButton = LogicalTreeHelper.FindLogicalNode(page, "OkClick") as Button;
window.Content = page;
window.ShowDialog();
here is the event listener:
private void OkClick(object sender, RoutedEventArgs e)
{
MessageBox.Show("Button in doc clicked");
window.Close();
}
and here is the XAML file that I'm using
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<Button Click="OkClick" Content="Ok" IsDefault="true" />
</StackPanel>
</Page>
The Xaml loads properly, but nothing happens when I click the button.