这是一个适用于 Windows Phone 8 的项目。
我尝试使用 XamlReader 加载包含多个对象的 Grid,其中一个是按钮。该按钮可以在 c# 中很好地创建、找到并附加一个处理程序,但似乎没有响应点击 - 按下时按钮不会改变颜色,并且没有调用关联的处理程序。
XamlReader 正在读取的 XAML 是
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name = "testgrid" Background = "Transparent">
<Button x:Name="btn" Content="Button" HorizontalAlignment="Left"
VerticalAlignment="Top" Margin="0,0,0,0" Grid.Row="1" Height="81"/>
<TextBlock Text = "Test"/>
</Grid>
使用的c#代码是
Grid tGrid = (Grid)XamlReader.Load(xaml);
Button tgtButton = (Button)tGrid.FindName("btn");
LayoutRoot.Children.Add((UIElement)tGrid);
tgtButton.Content = "bloop";
这里可能是什么问题?谢谢!
ps 如果加载的 xaml 只是一个按钮,使用相同的方法将其添加到 LayoutRoot,它会响应按下。