I'm a bit new to XAML and Caliburn.Micro. I ran into a "weird" issue.
I'm making a Windows Phone 8 application with Caliburn.Micro and I have a ListBox with items, which then includes another inner ListBox with some detail lines.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,5,12,5" >
<ListBox x:Name="CurrentStunts"
cal:Message.Attach="[Tap]=[Action OpenStuntOnWeb(CurrentStunts.SelectedItem)]">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid DataContext="{Binding}" Background="#FFCC00" Margin="0,10,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="45"/>
<ColumnDefinition Width="*" MinWidth="345"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="0">
<StackPanel.Background>
<ImageBrush ImageSource="{Binding StuntDetails.Channel,Converter={StaticResource ChannelIconConverter}}" Stretch="Uniform" AlignmentY="Top"/>
</StackPanel.Background>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical">
<TextBlock Text="{Binding Title}" Foreground="#CC0000" TextWrapping="Wrap"/>
<TextBlock Text="{Binding SubTitle}" Foreground="#336699" TextWrapping="Wrap"/>
<ListBox ItemsSource="{Binding DetailLines}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="#336699" FontSize="14" TextWrapping="Wrap"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Vertical">
<TextBlock Text="{Binding StuntDetails.NewPrice}" Foreground="#CC0000" />
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<TextBlock HorizontalAlignment="Left" Text="{Binding StuntDetails.OldPrice}" VerticalAlignment="Top" Grid.RowSpan="2" Foreground="#336699"/>
<Border BorderThickness="0,0,0,1" BorderBrush="#336699" >
</Border>
</Grid>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
The code in the viewmodel with cal:Message.Attach="[Tap]=[Action OpenStuntOnWeb(CurrentStunts.SelectedItem)]" is the following:
public void OpenStuntOnWeb(StuntSummary currentItem)
{
if (currentItem != null)
{
var uri = stuntManager.BuildStuntLink(currentItem.StuntDetails);
var webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = uri;
webBrowserTask.Show();
}
}
The problem is when booting the app and clicking anywhere on the inner ListBox (DetailLines) the parameter "currentItem" in the method public void OpenStuntOnWeb(StuntSummary currentItem) is null. When clicking on the outer ListBox CurrentStunts (such as on Title or SubTitle) it works fine and the parameter is filled in.
Even stranger is when you click on the outer ListBox and then click on the inner ListBox it also works fine and the parameter is filled in. It is only when first clicking on the inner ListBox that "currentItem" is null.
I'm stuck on this so any help would be greatly appreciated.