これは Windows Phone 8 用のプロジェクトです。
XamlReader を使用して、いくつかのオブジェクトを含む Grid を読み込もうとしましたが、そのうちの 1 つはボタンです。ボタンは 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 に追加すると、押すと応答します。