0

このWindows Phoneユーザーコントロールを作成しました:

ここに画像の説明を入力

XAML:

<Grid x:Name="LayoutRoot" Height="75" Width="353">
        <Image Height="50" HorizontalAlignment="Left" Margin="12,12,0,0" Name="img" Stretch="Fill" VerticalAlignment="Top" Width="50" />
        <TextBlock Height="50" HorizontalAlignment="Left" Margin="77,12,0,0" Name="txt" Text="TextBlock" VerticalAlignment="Top" Width="215" FontSize="32" />
        <CheckBox Content="CheckBox" Height="68" HorizontalAlignment="Right" Margin="0,3,10,0" Name="cb" VerticalAlignment="Top" Width="50" />
</Grid>

そして、私は自分のページの1つでそれをそのように呼んでいます

XAML.CS:

myListBox mls = new myListBox();
String[,] ls = { { "Text1", "/image/image1.png" }, { "Tex2", "/image/image2.png" } };
for (int i = 0; i < 2; i++)
{
        mls.txt.Text = ls[i, 0];
        mls.img.Source = url(ls[i, 1]);
}

public ImageSource url (string path)
{
        Uri uri = new Uri(path, UriKind.Absolute);
        ImageSource imgSource = new BitmapImage(uri);
        return imgSource;
}

私の問題は次のとおりです。

1)このように実行すると、以下のコードが表示されますが、for ループを変更して正常に動作するようにするとi<1(ただし、問題 2 のように見えるとは限りません)。

// Code to execute on Unhandled Exceptions
    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
    {
        if (System.Diagnostics.Debugger.IsAttached)
        {
            // An unhandled exception has occurred; break into the debugger
            System.Diagnostics.Debugger.Break();
        }
    }

2)このコードでテキストと画像を設定しましたが、画像は配置せず、テキストのみを配置しました。

4

1 に答える 1

1

同様の作業コードがあり、UriKind'Absolute' ではなく' Relative ' として使用しました。

後もう一つ。使用しているイメージのプロパティの下にある「ビルド アクション」が「リソース」などではなく「コンテンツ」に設定されていることを確認してください。

うまくいけばうまくいくでしょう。

于 2012-12-11T12:11:23.520 に答える