1

そこで、Windowsストアアプリ(別名Windows 8アプリケーション/以前はMetroアプリと呼ばれていました)を作成し、画像を含むzipアーカイブをインポートします(インポートは正常に機能します)。

zipが(それ自体のフォルダーに)抽出されると、そのフォルダーを表すオブジェクトをObservableCollectionに追加します。

このObservableCollectionはGridViewへのDataContextとして使用され、フォルダーの名前は正しく表示されますが、フォルダーの最初の画像は...<=ではないので問題が発生します。

抽出が完了した後、静的メソッドを使用してオブジェクトを作成します

public class ZipFolder
    {

        public string Title
        {
            get { return _title; }
            set { _title = value;}
        }
        public int CurrentPage
        {
            get { return _currentPage; }
            set { _currentPage = value;}
        }
        public Uri PathCover
        {
            get { return _pathCover;  }
            set { _pathCover = value;}
        }

        private string _title ;
        private int _currentPage;
        private Uri _pathCover;

    }
public static async Task<ZipFolderObject> CreateComic(StorageFolder folder)
{
    ZipFolderObject o = new ZipFolderObject();
    o.Title = folder.DisplayName;

    IReadOnlyList<StorageFile> asyncOperation = await folder.GetFilesAsync();
    StorageFile cover = asyncOperation[0];

    o.PathCover = new Uri("ms-appdata:///local/" + folder.Name + "/" + cover.Name);

    return o;
}

そして、バインディングは次のようになります。

<DataTemplate x:Key="zipFolderItemTemplate">
        <StackPanel Width="165" Height="250">
            <Grid Height="215">
                <Border Background="Bisque" Width="{Binding ActualWidth, ElementName=image}">
                    <!--<Image x:Name="image" VerticalAlignment="Top" HorizontalAlignment="Center" Source="{Binding Cover}" />-->
                    <Image Stretch="Uniform" x:Name="image" VerticalAlignment="Top" HorizontalAlignment="Center">
                        <Image.Source>
                            <BitmapImage   UriSource="{Binding PathCover}" />
                        </Image.Source>
                    </Image>
                </Border>
                <Polygon Points="0,0 0,50, 50,0" Stroke="Red" FillRed" RenderTransformOrigin="0.5,0.5" Visibility="{Binding CurrentPage, Converter={StaticResource BookmarkVisibilityConverter}}" Width="{Binding ActualWidth, ElementName=image}" />
            </Grid>
            <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding Title}" Margin="0,10,0,0" Foreground="Black" />
        </StackPanel>
    </DataTemplate>

だから誰かが私の問題へのヒントを持っているならそれは素晴らしいでしょう!

4

2 に答える 2

1

Image Source の directory/filename.ext のみを使用できます。イメージを抽出した場合、サブディレクトリです。2 つの値を連結し、PathCover プロパティに設定します。

 folder.Name + "/" + cover.Name

このセクションで Data Templatete を編集します。

<Image Stretch="Uniform" x:Name="image" VerticalAlignment="Top" HorizontalAlignment="Center" Source={Binding PathCover}/>  

よろしく。

于 2012-12-12T18:32:50.303 に答える