【发布时间】:2014-05-18 20:13:09
【问题描述】:
我有这个 XAML
(...)
<ListBox Height="Auto" Margin="0,0,-20,0" x:Name="post_Images_Grid_list" VerticalAlignment="Top" HorizontalContentAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="Auto" Height="Auto" Background="#FF#247722" Margin="0,0,10,20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="19*"/>
</Grid.ColumnDefinitions>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal" Margin="0">
<Image Source="{Binding image, Mode=OneWay}" Width="110" Height="110" Margin="5" Stretch="UniformToFill" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
(...)
MyPage.xaml.cs 中的这个 C# 代码:
(...)
post_Images_Grid_list.ItemsSource = thePost.images;
(...)
thePost.images 的定义:
public List<BitmapImages> images = new List<BitmapImages>();
还有 BitmapImages 类:
public class BitmapImages
{
public BitmapImage image { get; set; }
public BitmapImages(string image_url)
{
this.image = new BitmapImage(new Uri(image_url, UriKind.RelativeOrAbsolute));
}
}
但是xaml页面显示完成后,debug跳转到App.xaml.cs中的Application_UnhandledException方法,是什么问题?
这是List images在运行时的数据:
在我看来一切都是正确的!每个 URL 都存在并且有一个图像,我在网络浏览器中检查了。
感谢您的帮助,我不知道发生了什么!。
谢谢你,Rohit Vats,这里是 e.Exception:
- e.ExceptionObject {MS.Internal.WrappedException:错误 HRESULT E_FAIL 已从对 COM 组件的调用中返回。 ---> System.Exception:对 COM 组件的调用已返回错误 HRESULT E_FAIL。 在 MS.Internal.XcpImports.CheckHResult(UInt32 小时) 在 MS.Internal.XcpImports.UIElement_Measure(UIElement 元素,Size availableSize) 在 System.Windows.UIElement.Measure(可用大小) 在 Microsoft.Phone.Controls.WrapPanel.MeasureOverride(大小约束) 在 System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget,双 inWidth,双 inHeight,Double& outWidth,Double& outHeight) --- 内部异常堆栈跟踪结束 ---} System.Exception {MS.Internal.WrappedException}
好像和xaml图片元素的大小有关?
【问题讨论】:
-
在这里发布错误消息。
-
> MSFTInsider.DLL!MSFTInsider.App.Application_UnhandledException(object sender = {MSFTInsider.App}, System.Windows.ApplicationUnhandledExceptionEventArgs e = {System.Windows.ApplicationUnhandledExceptionEventArgs}) Línea 127 C#
-
App.xaml.cs 中的Debugger.Break()。应用代码中没有异常
-
调试器在 App.xaml.cs 中中断,因为存在一些未处理的错误并使其成为未处理的异常方法。检查
e.Exception的错误消息。 -
添加到问题中,对于 cmets 来说太长了。
标签: c# wpf xaml exception binding