[英]C# windows phone xaml showing invalid xaml error
您好,我正在開發Windows Phone應用,下面的一些代碼顯示一條藍線,上面寫着“ invalid xaml”,但在編譯或運行時沒有問題。 我將圖像轉換為字節以將其存儲在isostorage中,並且在綁定時將其轉換回。 我的代碼是:
<StackPanel Height="auto" Orientation="Horizontal" Margin="0,0,0,0" Grid.RowSpan="2">
<StackPanel Width="80" Orientation="Horizontal" Height="auto" VerticalAlignment="Top" HorizontalAlignment="Left">
<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="auto" 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" />
<StackPanel>
<ListBox SelectionChanged="Contactlist2_SelectionChanged_1" ScrollViewer.VerticalScrollBarVisibility="Disabled" x:Name="Contactlist2" ItemsSource="{Binding PhoneNumbers}" Margin="10,0,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Height="auto" Margin="5,0,0,0">
<TextBlock FontSize="25" Text="{Binding}" FontFamily="Segoe WP" Margin="10,0,0,0" Width="320" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" />
<TextBlock FontSize="20" Text="mobile" Width="302"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</StackPanel>
</StackPanel>
如果我刪除
ImageSource="{Binding imageBytes, Converter={StaticResource BytesToImageConverter}}"
我的轉換器代碼是:
public class BytesToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && value is byte[])
{
byte[] bytes = value as byte[];
MemoryStream stream = new MemoryStream(bytes);
BitmapImage image = new BitmapImage();
image.DecodePixelType = DecodePixelType.Logical;
image.CreateOptions = BitmapCreateOptions.BackgroundCreation;
image.CreateOptions = BitmapCreateOptions.DelayCreation;
var bitmapImage = PictureDecoder.DecodeJpeg(stream, 480, 856);
if (bitmapImage.PixelHeight > bitmapImage.PixelWidth)
{
image.DecodePixelWidth = 56;
image.DecodePixelHeight = 100;
}
else
{
image.DecodePixelWidth = 100;
image.DecodePixelHeight = 56;
}
image.SetSource(stream);
return image;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
從圖像錯誤消失。 怎么了? 謝謝。
這是由於名稱空間或項目名稱中存在空格。 圍繞這種情況一直存在問題。 我以為Microsoft解決了這個特定問題:0 /
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.