Not*_*Bot 1 c# wpf xaml windows-phone-8
我正在开发一款适用于Windows手机的应用程序,它主要包括手机通讯录.我正在使用Contacts类获取所有电话联系人,并且我将联系人数据存储在隔离存储中.由于我无法序列化图像,我在序列化之前将它们转换为byte [].我的代码是:
foreach (var result in e.Results)
{
if (result.PhoneNumbers.FirstOrDefault() != null)
{
BitmapImage bmp2 = new BitmapImage();
bmp2.SetSource(result.GetPicture());
listobj.Add(new AddressBook()
{
FirstName = result.DisplayName ?? "",
imageBytes = AddressBook.imageConvert(bmp2),
EmailAddress = "",
LastName = "",
Phone = result.PhoneNumbers.FirstOrDefault().PhoneNumber ?? "",
});
}
}
Run Code Online (Sandbox Code Playgroud)
当Contact没有图片时,它会在行上显示Argument null异常错误:
bmp2.SetSource(result.GetPicture());
Run Code Online (Sandbox Code Playgroud)
因此,当联系人图像为null时,我想使用一些自定义图像("/Images/ci2.png"或任何空白图像也可以使用).我的xaml代码是:
<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 imageByte, 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" Margin="5,0,0,-12" Width="320" HorizontalAlignment="Left" VerticalAlignment="Top">
<TextBlock.Foreground>
<SolidColorBrush Color="#FFCFC9C9"/>
</TextBlock.Foreground></TextBlock>
</StackPanel>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
我的问题是,我怎样才能使用自定义图像
bmp2.SetSource(result.GetPicture());
Run Code Online (Sandbox Code Playgroud)
一片空白?谢谢
快速看一下,你不能这样做:
if (result.GetPicture() != null)
{
bmp2.SetSource(result.GetPicture());
}
else
{
bmp2.SetSource(Application.GetResourceStream(new Uri(@"Images/ci2.png", UriKind.Relative)).Stream);
}
Run Code Online (Sandbox Code Playgroud)
如果没有,我已经为此实现了不同的解决方案,并且可能会发布更多细节.
| 归档时间: |
|
| 查看次数: |
119 次 |
| 最近记录: |