1

This is a project for Windows Phone 8.

I have tried using a XamlReader to load a Grid containing several objects, one of which is a button. The button can be created fine, found, and attached a handler in c#, but does not seem to respond to clicks - the button doesn't change colour when pressed, and no associated handlers are called.

The XAML being read by XamlReader is

<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>

The c# code used is

Grid tGrid = (Grid)XamlReader.Load(xaml);
Button tgtButton = (Button)tGrid.FindName("btn");      
LayoutRoot.Children.Add((UIElement)tGrid);
tgtButton.Content = "bloop";

What could be the problem here? Thanks!

p.s. If the loaded xaml is a button only, using the same method to add it to the LayoutRoot, it does respond to pressing.

1 Answers1

0

A very very basic error - I had neglected to arrange the controls properly by not defining grid rows. The TextBlock was on top of the Button - even though text was not entirely covering the area, it seems the transparent parts of it still obstruct the button. The lesson learned is this has nothing to do with logical trees or initializations!