我在我的 WPF 项目中使用XamlReader 。它有效(我的参考)
我当前的示例 Xaml 是这样的:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="800" Height="600">
<Button Name="Test1" Content="Test1" Width="357" Height="88" Margin="14,417,0,0" ></Button>
<Button Name="Test2" Content="Test2" Width="357" Height="88" Margin="14,529,0,0" ></Button>
</Grid>
并像这样添加按钮的点击事件:
button = LogicalTreeHelper.FindLogicalNode(rootObject, "Test1") as Button ;
button.Click += new RoutedEventHandler(Button1_Click);
可以这样写xaml吗?
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="800" Height="600">
<Button Name="Test1" Content="Test1" ... Click="Button1_Click"></Button>
<Button Name="Test2" Content="Test2" ... Click="Button2_Click"></Button>
</Grid>