0

したがって、問題は次のようになります。

ソリューション エクスプローラーで Images という名前のフォルダーを作成し、いくつかの .png を追加したので、ファイル構造は /MyProject/Images/image.png のようになります。ファイルのプロパティで、Build Action を Content に設定し、Copy to Output を Copy always に設定します。

次のような画像を表示しようとしています。

<Image Source="{Binding ImageUri}" Height="*" Width="*"/>

長いリストセレクターで画像を表示しようとしているので、デザイナー用のサンプルデータを作成しました:

<vm:MainViewModel.Items>
    <vm:ItemViewModel PageName="page1"  ImageUri="/Images/image1.png"/>
    <vm:ItemViewModel PageName="page2"  ImageUri="/Images/image2.png"/>
</vm:MainViewModel.Items>

XAML デザイナーでは、すべて問題ないように見えます。リストは、イメージとその横のテキストというように、希望どおりに表示されます。

コードでは、次のように画像を追加しています。

this.Items.Add(new ItemViewModel() { PageName = "page1", ImageUri = new Uri(@"/Images/image1.png", UriKind.RelativeOrAbsolute) });

ただし、デバイスでアプリケーションを起動しようとすると。次の例外に遭遇しました:

Error HRESULT E_FAIL has been returned from a call to a COM component.

および次のスタックトレース:

at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options)
   at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom)
   at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom)
   at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated)
   at Microsoft.Phone.Controls.LongListSelector.Balance()
   at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)

もちろん、XAML でイメージをコメント アウトして、テキストだけを残すと、アプリケーションはクラッシュしなくなります。では、これらのイメージをどのように組み込むことができ、後でそれらを取得するにはどうすればよいでしょうか?

4

1 に答える 1