Windows phone app xaml error
- by thewarri0r9
i am developing an app for windows phone 8 and i stuck on this code which visual studio showing invalid xaml. But Code compiles and works well. Invalid xaml Code is :
<DataTemplate x:Key="AddrBookItemTemplate">
<StackPanel Margin="0,0,0,2" Orientation="Horizontal">
<StackPanel Width="80" Orientation="Horizontal" Height="80">
<Ellipse Margin="0" Height="70" Width="70" HorizontalAlignment="Left" Stroke="{x:Null}">
<Ellipse.Fill>
<ImageBrush Stretch="Fill" ImageSource="{Binding imageBytes, Converter={StaticResource BytesToImageConverter}}"/>
</Ellipse.Fill>
</Ellipse>
</StackPanel>
<StackPanel Height="80" Margin="0" Width="380" HorizontalAlignment="Left">
<TextBlock FontWeight="Bold" Text="{Binding FirstName}" FontFamily="Segoe WP Semibold" FontSize="30" VerticalAlignment="Top" Margin="5,0,0,0" HorizontalAlignment="Left" />
<TextBlock Text="{Binding Phone}" FontFamily="Segoe WP" FontSize="24" Foreground="{StaticResource PhoneTextBoxReadOnlyBrush}" Margin="5,0,0,-12" Width="320" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</StackPanel>
</StackPanel>
</DataTemplate>
I am serializing image by converting it to byte, it works fine but if image is null it gives an error.
code behind:
if (e.Results != null)
{
List<AddressBook> source = new List<AddressBook>();
foreach (var result in e.Results)
{
if (result.PhoneNumbers.FirstOrDefault() != null && result.GetPicture()!=null)
{
BitmapImage bmp = new BitmapImage();
BitmapImage nullbmp = new BitmapImage();
if (result.GetPicture() == null)
{
bmp.UriSource = new Uri(@"/Images/ci2.png", UriKind.RelativeOrAbsolute);
}
else
{
bmp.SetSource(result.GetPicture());
}
listobj.Add(new AddressBook()
{
FirstName = result.DisplayName != null ? result.DisplayName : "",
imageBytes = AddressBook.imageConvert(bmp),
EmailAddress = "",
LastName = "",
Phone = result.PhoneNumbers.FirstOrDefault() != null ? result.PhoneNumbers.FirstOrDefault().PhoneNumber : "",
});
}
}
Above code show an error "object reference not set to instance of an object". I want to show the default image (or color) in ellipse when image is null.What should I do?