0

私のアプリケーションでは、ソーシャル ネットワーク vkontakte (ロシアの facebook:) からのニュースフィードを表示します。サーバーにリクエストを送信し、約 50 のニュースフィード項目を含む xml ファイルを受け取ります。xml の例 (50 の 2 項目)

    <item>
  <type>post</type>
  <source_id>-26406986</source_id>
  <date>1356207001</date>
  <post_id>1058858</post_id>
  <text>#Суть на #lm.</text>
  <attachment>
    <type>photo</type>
    <photo>
      <pid>293678498</pid>
      <aid>-7</aid>
      <owner_id>-26406986</owner_id>
      <user_id>65647811</user_id>
      <src>http://cs406928.userapi.com/v406928811/61c7/Rjee0rUq3vU.jpg</src>
      <src_big>http://cs406928.userapi.com/v406928811/61c8/PSYiLcxlv9s.jpg</src_big>
      <src_small>http://cs406928.userapi.com/v406928811/61c6/26XXAbejR7U.jpg</src_small>
      <width>186</width>
      <height>604</height>
      <text />
      <created>1356203380</created>
      <access_key>ca379f61ca5de866ae</access_key>
    </photo>
  </attachment>
  <attachments list="true">
    <attachment>
      <type>photo</type>
      <photo>
        <pid>293678498</pid>
        <aid>-7</aid>
        <owner_id>-26406986</owner_id>
        <user_id>65647811</user_id>
        <src>http://cs406928.userapi.com/v406928811/61c7/Rjee0rUq3vU.jpg</src>
        <src_big>http://cs406928.userapi.com/v406928811/61c8/PSYiLcxlv9s.jpg</src_big>
        <src_small>http://cs406928.userapi.com/v406928811/61c6/26XXAbejR7U.jpg</src_small>
        <width>186</width>
        <height>604</height>
        <text />
        <created>1356203380</created>
        <access_key>ca379f61ca5de866ae</access_key>
      </photo>
    </attachment>
  </attachments>
  <comments>
    <count>47</count>
    <can_post>1</can_post>
  </comments>
  <likes>
    <count>167</count>
    <user_likes>0</user_likes>
    <can_like>1</can_like>
    <can_publish>1</can_publish>
  </likes>
  <reposts>
    <count>35</count>
    <user_reposted>0</user_reposted>
  </reposts>
  <post_source>
    <type>vk</type>
  </post_source>
</item>

各アイテムには、異なるコンテンツ<attachments>(テキスト、写真、ビデオ、オーディオ、ドキュメント、テキストと写真、テキストとオーディオ、およびこの譜表の可能なすべての組み合わせ) を含めることができます。私はすでにここでこの質問をしました。そして、私には答えがありました-テンプレートセレクターを使用してください。ええと...私はそれを使用しました、そして今私は16listboxの異なるアイテムを持っています、そしてそれはすべての可能な組み合わせではありません. xaml の非常に巨大なコードです。例、2 つのテンプレート:

ビデオとオーディオ

      <!--VideonAudios-->          <local:NewsTemplateSelector.VideonAudios>
                                <DataTemplate>
                                    <Grid Name="VideoGrid" MaxHeight="2000" Tap="ListBoxTap"   >
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="75"/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="75"/>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="28"/>
                                        </Grid.RowDefinitions>
                                        <Image Source="{Binding SourceImage}" Tap="GetUserInfo"  Width="75"/>
                                        <TextBlock Text="{Binding SourceName}"   FontSize="25" Grid.Column="1" TextWrapping="Wrap" />
                                        <TextBlock Grid.Column="1" TextWrapping="Wrap" Text="{Binding Copy_owner_name}"    FontSize="25" VerticalAlignment="Bottom" Margin="39,0,0,0" MaxHeight="35"/>
                                        <Image Source="{Binding Copy_owner_photo}" Grid.Column="1" HorizontalAlignment="Left" Height="35" Width="39" VerticalAlignment="Bottom" />
                                        <TextBlock Text="{Binding Video[0].Title}"    FontSize="25" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap"  VerticalAlignment="Top" Height="auto" />
                                        <Image Source="{Binding Video[0].Big}" Margin="10" Grid.Column="1" Grid.Row="2" Tap="Video_Tap"  />
                                        <ListBox Name="audiosListbox" ItemsSource="{Binding Audio}"  MaxHeight="500" Margin="10" Grid.Column="1" Grid.Row="3" >
                                            <ListBox.ItemTemplate>
                                                <DataTemplate>
                                                    <Grid>
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="100"/>
                                                            <ColumnDefinition/>
                                                        </Grid.ColumnDefinitions>
                                                        <TextBlock Text="{Binding Title}" TextWrapping="Wrap" Grid.Column="1"   FontSize="25" Tap="AudioTitleTap" />
                                                        <Button Content="Play"  Height="70" Tap="Audios_Button_Click" />
                                                        <TextBox Text="{Binding Count}" Tag="Count" Visibility="Collapsed" />
                                                    </Grid>
                                                </DataTemplate>
                                            </ListBox.ItemTemplate>
                                        </ListBox>
                                        <Image Source="\icons\appbar.check.rest.png" Grid.Column="1" HorizontalAlignment="Right" Grid.Row="4" Width="30" Margin="0,1.5,34,-1.5" d:LayoutOverrides="VerticalMargin"/>
                                        <TextBlock Text="{Binding Time}" Grid.Column="1" HorizontalAlignment="Left" Grid.Row="4"  />
                                        <TextBlock Text="{Binding Likes}" Name="LikeTxtBox" Grid.Column="1" HorizontalAlignment="Right" Grid.Row="4"   TextWrapping="Wrap" Width="30" Margin="0,0.5,0,-0.5"/>
                                        <Line X1="0" Y1="27" X2="420" Y2="27" Margin="0,-28,0,0" Stroke="Gray" StrokeThickness="1" Grid.Column="1"  />
                                        <Line X1="0" Y1="27" X2="80" Y2="27" Margin="0,-28,0,0" Stroke="Gray" StrokeThickness="1" />
                                        <TextBox Text="{Binding Video[0].Url}" Tag="VURL" Visibility="Collapsed" />
                                    </Grid>
                                </DataTemplate>
                            </local:NewsTemplateSelector.VideonAudios>

そして、その 16 のテンプレートは 2 つだけです。 1

2

3

しかし、リストボックスが奇妙な動作をすることがあります。このテンプレートが原因だと思います。そして今、別のページに同様のリストボックスを作成する必要があり、テンプレートセレクターを使用するのはお勧めできません。誰でも教えてもらえますlistboxか? 異なるコンテンツのアイテムを作成する別の方法はありますか?

UPD:xmlを解析する方法

 void c_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
      //  string str = null;
        XDocument xml = XDocument.Load(e.Result); //полученый xml от апи вконтакта
        MessageBox.Show(xml.ToString());
        var inf = from c in xml.Descendants("item") // 
                  select c;
        int j = -1;
        int i = 0;
        App.New_From = (string)xml.Element("response").Element("new_from").Value;
        foreach (var item in inf)
        {
            #region static info
            i++;
            if (inf.Count() > i)
            {
                if ((string)item.Element("type").Value != "friend")
                {
                    New new1 = new New();
                    if ((string)item.Element("source_id").Value != null)
                    {
                        new1.SourseId = (string)item.Element("source_id").Value;
                    }
                    if ((string)item.Element("date").Value != null)
                    {
                       // MessageBox.Show(item.Element("date").Value);
                        new1.Time = App.GetTime(item.Element("date").Value);
                      //  MessageBox.Show(App.GetTime(item.Element("date").Value));
                    }
                    if (item.Element("photos") != null)
                    {
                        var photos = from c in item.Descendants("photo") // 
                                     select c;
                        foreach (var ph in photos)
                        {
                            PhotoAttachment photo = new PhotoAttachment();
                            photo.OwnerId = ph.Element("owner_id").Value;
                            photo.PId = ph.Element("pid").Value;
                            photo.Small = ph.Element("src_small").Value;
                            photo.Big = ph.Element("src_big").Value;
                            if (ph.Element("src_xxbig") != null)
                                photo.xBig = ph.Element("src_xxbig").Value;
                            else if (ph.Element("src_xbig") != null)
                                photo.xBig = ph.Element("src_xbig").Value;
                            else
                                photo.xBig = ph.Element("src_big").Value;
                            new1.photoAttachments.Add(photo);
                        }
                    }
                    if (item.Element("copy_owner_id") != null)
                    {
                        new1.Copy_owner_id = (string)item.Element("copy_owner_id").Value;
                    }
                    if (item.Element("post_id") != null)
                    {
                        new1.Post_id = (string)item.Element("post_id").Value;
                    }
                    if ((string)item.Element("text") != null)
                    {
                        new1.Texts = (string)item.Element("text");
                    }
                    if ((string)item.Element("comment") != null)
                        new1.Comments = (string)item.Element("comment").Element("count").Value;
                    if ((string)item.Element("likes") != null)
                        new1.Likes = (string)item.Element("likes").Element("count").Value;
            #endregion
                    if (item.Element("attachment") != null)
                    {
                        var vd = from c in item.Descendants("attachment")
                                 select c;
                        foreach (var content in vd)
                        {

                            if (content.Element("audio") != null)
                            {
                                AudioAttachment audio = new AudioAttachment();
                                audio.Title = (string)content.Element("audio").Element("title").Value;
                                audio.Perfomer = (string)content.Element("audio").Element("performer").Value;
                                string tmp = audio.Perfomer + " - " + audio.Title;
                                audio.Title = tmp;
                                audio.OwnerId = (string)content.Element("audio").Element("owner_id").Value;
                                audio.Audio_Id = (string)content.Element("audio").Element("aid").Value;
                                audio.Duration = (string)content.Element("audio").Element("duration").Value;
                                audio.Url = audio.OwnerId + "_" + audio.Audio_Id;
                                audio.Count = j++;
                                if (new1.audioAttachments.Count > 0)
                                {
                                    if (audio.Audio_Id == new1.audioAttachments[0].Audio_Id)
                                    {
                                        new1.audioAttachments.RemoveAt(0);
                                    }
                                }
                                new1.audioAttachments.Add(audio);
                            }
                            if (content.Element("photo") != null)
                            {
                                PhotoAttachment photo = new PhotoAttachment();
                                photo.OwnerId = (string)content.Element("photo").Element("owner_id").Value;
                                photo.PId = (string)content.Element("photo").Element("pid").Value;
                                photo.Small = (string)content.Element("photo").Element("src_small").Value;
                                photo.Big = (string)content.Element("photo").Element("src_big").Value;
                                if (content.Element("photo").Element("src_xxbig") != null)
                                    photo.xBig = (string)content.Element("photo").Element("src_xxbig").Value;
                                else if (content.Element("photo").Element("src_xbig") != null)
                                    photo.xBig = (string)content.Element("photo").Element("src_xbig").Value;
                                else
                                    photo.xBig = (string)content.Element("photo").Element("src_big").Value;
                                if (new1.photoAttachments.Count > 0)
                                {
                                    if (photo.Big == new1.photoAttachments[0].Big)
                                    {
                                        new1.photoAttachments.RemoveAt(0);
                                    }
                                }
                                new1.photoAttachments.Add(photo);
                            }

                            if (content.Element("video") != null)
                            {
                                VideoAttachment video = new VideoAttachment();
                                video.Title = (string)content.Element("video").Element("title").Value;
                                video.Description = (string)content.Element("video").Element("description").Value;
                                video.OwnerId = (string)content.Element("video").Element("owner_id").Value;
                                if ((string)content.Element("video").Element("image_small") != null)
                                    video.Small = (string)content.Element("video").Element("image_small").Value;
                                if ((string)content.Element("video").Element("image_big") != null)
                                    video.Big = (string)content.Element("video").Element("image_big").Value;
                                video.Video_Id = (string)content.Element("video").Element("vid").Value;
                                video.Url = video.OwnerId + "_" + video.Video_Id;
                                if (new1.videoAttachments.Count > 0)
                                {
                                    if (video.Big == new1.videoAttachments[0].Big)
                                    {
                                        new1.videoAttachments.RemoveAt(0);
                                    }

                                }
                                new1.videoAttachments.Add(video);
                            }

                            if (content.Element("link") != null)
                            {
                                new1.Priority = PostType.Link;
                                new1.Url.Title = (string)content.Element("link").Element("title").Value;
                                new1.Url.Description = (string)content.Element("link").Element("description").Value;
                                new1.Url.Url = (string)content.Element("link").Element("url").Value;
                                if ((string)content.Element("link").Element("image_src") != null)
                                    new1.Url.Image = (string)content.Element("link").Element("image_src").Value;
                                else if (new1.photoAttachments.Count > 0 && new1.photoAttachments[0].Big != null)
                                    new1.Url.Image = new1.photoAttachments[0].Big;
                                else if (new1.photoAttachments.Count > 0 && new1.photoAttachments[1].Big != null)
                                    new1.Url.Image = new1.photoAttachments[1].Big;

                            }
                        }
                    }

                    if (item.Element("comments") != null)
                    {
                        if (item.Element("comments").Element("can_post") != null)
                            new1.CanPost = Convert.ToInt32(item.Element("comments").Element("can_post").Value);
                    }


                    //str += string.Format("{0} {1} {2}\n", NewsList.Count, new1.audioAttachments.Count, new1.photoAttachments.Count);

                    if (new1.photoAttachments.Count == 0 && new1.videoAttachments.Count == 0 && new1.audioAttachments.Count == 0 && new1.urlAttachment.Url == null) new1.Priority = PostType.Text;
                    if (new1.photoAttachments.Count == 1 && new1.videoAttachments.Count == 0 && new1.audioAttachments.Count == 0 && new1.urlAttachment.Url == null) new1.Priority = PostType.Photo;
                    if (new1.photoAttachments.Count > 1 && new1.videoAttachments.Count == 0 && new1.audioAttachments.Count == 0 && new1.urlAttachment.Url == null) new1.Priority = PostType.Photos;
                    if (new1.photoAttachments.Count == 0 && new1.videoAttachments.Count == 1 && new1.audioAttachments.Count == 0 && new1.urlAttachment.Url == null) new1.Priority = PostType.Video;
                    if (new1.photoAttachments.Count == 0 && new1.videoAttachments.Count > 1 && new1.audioAttachments.Count == 0 && new1.urlAttachment.Url == null) new1.Priority = PostType.Videos;
                    if (new1.photoAttachments.Count == 0 && new1.videoAttachments.Count == 0 && new1.audioAttachments.Count == 1 && new1.urlAttachment.Url == null) new1.Priority = PostType.Audio;
                    if (new1.photoAttachments.Count == 0 && new1.videoAttachments.Count == 0 && new1.audioAttachments.Count > 1 && new1.urlAttachment.Url == null) new1.Priority = PostType.Audios;
                    if (new1.photoAttachments.Count == 1 && new1.videoAttachments.Count == 0 && new1.audioAttachments.Count == 1 && new1.urlAttachment.Url == null) new1.Priority = PostType.PhotonAudio;
                    if (new1.photoAttachments.Count == 1 && new1.videoAttachments.Count == 0 && new1.audioAttachments.Count > 1 && new1.urlAttachment.Url == null) new1.Priority = PostType.PhotonAudios;
                    if (new1.photoAttachments.Count > 1 && new1.videoAttachments.Count == 0 && new1.audioAttachments.Count == 1 && new1.urlAttachment.Url == null) new1.Priority = PostType.PhotosnAudio;
                    if (new1.photoAttachments.Count > 1 && new1.videoAttachments.Count == 0 && new1.audioAttachments.Count > 1 && new1.urlAttachment.Url == null) new1.Priority = PostType.PhotosnAudios;
                    if (new1.photoAttachments.Count == 0 && new1.videoAttachments.Count == 1 && new1.audioAttachments.Count == 1 && new1.urlAttachment.Url == null) new1.Priority = PostType.VideonAudio;
                    if (new1.photoAttachments.Count == 0 && new1.videoAttachments.Count == 1 && new1.audioAttachments.Count > 1 && new1.urlAttachment.Url == null) new1.Priority = PostType.VideonAudios;
                    if (new1.photoAttachments.Count == 0 && new1.videoAttachments.Count > 1 && new1.audioAttachments.Count == 1 && new1.urlAttachment.Url == null) new1.Priority = PostType.VideosnAudio;
                    if (new1.photoAttachments.Count == 0 && new1.videoAttachments.Count > 1 && new1.audioAttachments.Count > 1 && new1.urlAttachment.Url == null) new1.Priority = PostType.VideosnAudios;


                    NewsList.Add(new1);
                    new1 = null;
                }
            }

次のようなことができますか

    <local:NewsTemplateSelector.Content.Audios>
<ListBox Name="audiosListbox" ItemsSource="{Binding Audio}"  MaxHeight="500" Margin="10" Grid.Column="1" Grid.Row="3" >
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding Title}" TextWrapping="Wrap" Grid.Column="1"   FontSize="25" Tap="AudioTitleTap" />
                <Button Content="Play"  Height="70" Tap="Audios_Button_Click" />
                <TextBox Text="{Binding Count}" Tag="Count" Visibility="Collapsed" />
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
<local:NewsTemplateSelector.Content.Audios>

画像、ビデオ、ビデオなどについても同様です。そして、次のように使用します

<!--Audios-->
<local:NewsTemplateSelector.Audios>
<DataTemplate>
    <Grid Name="AudiosGrid" MaxHeight="2000" Tap="ListBoxTap"    >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="75"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="75"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="28"/>
        </Grid.RowDefinitions>
        <Image Source="{Binding SourceImage}" Tap="GetUserInfo"  Width="75"/>
        <TextBlock Text="{Binding SourceName}"   FontSize="25" Grid.Column="1" TextWrapping="Wrap" />
        <TextBlock Grid.Column="1" TextWrapping="Wrap" Text="{Binding Copy_owner_name}"    FontSize="25" VerticalAlignment="Bottom" Margin="39,0,0,0" MaxHeight="35"/>
        <Image Source="{Binding Copy_owner_photo}" Grid.Column="1" HorizontalAlignment="Left" Height="35" Width="39" VerticalAlignment="Bottom" />
        <TextBlock Text="{Binding Texts}"    FontSize="25" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap"  VerticalAlignment="Top" Height="auto" />
        <local:NewsTemplateSelector.Content.Audios>
        </local:NewsTemplateSelector.Content.Audios>
        <Image Source="\icons\appbar.check.rest.png" Grid.Column="1" HorizontalAlignment="Right" Grid.Row="3" Width="30" Margin="0,1.5,34,-1.5" d:LayoutOverrides="VerticalMargin"/>
        <TextBlock Text="{Binding Time}" Grid.Column="1" HorizontalAlignment="Left" Grid.Row="3"  />
        <TextBlock Text="{Binding Likes}" Name="LikeTxtBox" Grid.Column="1" HorizontalAlignment="Right" Grid.Row="3"   TextWrapping="Wrap" Width="30" Margin="0,0.5,0,-0.5"/>
        <Line X1="0" Y1="27" X2="420" Y2="27" Margin="0,-28,0,0" Stroke="Gray" StrokeThickness="1" Grid.Column="1"  />
        <Line X1="0" Y1="27" X2="80" Y2="27" Margin="0,-28,0,0" Stroke="Gray" StrokeThickness="1" />
    </Grid>
</DataTemplate>

ではない

<!--Audios-->
<local:NewsTemplateSelector.Audios>
<DataTemplate>
    <Grid Name="AudiosGrid" MaxHeight="2000" Tap="ListBoxTap"    >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="75"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="75"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="28"/>
        </Grid.RowDefinitions>
        <Image Source="{Binding SourceImage}" Tap="GetUserInfo"  Width="75"/>
        <TextBlock Text="{Binding SourceName}"   FontSize="25" Grid.Column="1" TextWrapping="Wrap" />
        <TextBlock Grid.Column="1" TextWrapping="Wrap" Text="{Binding Copy_owner_name}"    FontSize="25" VerticalAlignment="Bottom" Margin="39,0,0,0" MaxHeight="35"/>
        <Image Source="{Binding Copy_owner_photo}" Grid.Column="1" HorizontalAlignment="Left" Height="35" Width="39" VerticalAlignment="Bottom" />
        <TextBlock Text="{Binding Texts}"    FontSize="25" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap"  VerticalAlignment="Top" Height="auto" />
        <ListBox Name="audiosListbox" ItemsSource="{Binding Audio}"  MaxHeight="500" Margin="10" Grid.Column="1" Grid.Row="2" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{Binding Title}" TextWrapping="Wrap" Grid.Column="1"   FontSize="25" Tap="AudioTitleTap" />
                        <Button Content="Play"  Height="70" Tap="Audios_Button_Click" />
                        <TextBox Text="{Binding Count}" Tag="Count" Visibility="Collapsed" />
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Image Source="\icons\appbar.check.rest.png" Grid.Column="1" HorizontalAlignment="Right" Grid.Row="3" Width="30" Margin="0,1.5,34,-1.5" d:LayoutOverrides="VerticalMargin"/>
        <TextBlock Text="{Binding Time}" Grid.Column="1" HorizontalAlignment="Left" Grid.Row="3"  />
        <TextBlock Text="{Binding Likes}" Name="LikeTxtBox" Grid.Column="1" HorizontalAlignment="Right" Grid.Row="3"   TextWrapping="Wrap" Width="30" Margin="0,0.5,0,-0.5"/>
        <Line X1="0" Y1="27" X2="420" Y2="27" Margin="0,-28,0,0" Stroke="Gray" StrokeThickness="1" Grid.Column="1"  />
        <Line X1="0" Y1="27" X2="80" Y2="27" Margin="0,-28,0,0" Stroke="Gray" StrokeThickness="1" />
    </Grid>
</DataTemplate>

4

1 に答える 1

0

通常、根本的に異なるコンテンツ (ビデオと画像、テキストのみなど) を持つ各 XML コンポーネントには、異なるテンプレートが必要です。ただし、テンプレートを別の XAML ファイルに定義し、リソース ディクショナリとして各コントロールに追加する必要があります。このようにして、テンプレートを 1 か所で定義し、何もコピー/貼り付けすることなく、すべてのコントロールにインポートできます。を使用して、この方法で複数の XAML ファイルをインポートすることもできますMergedDictionary

そのサイトから XML ファイルをどのように読み取ったかはわかりませんが、コード ビハインドで、より単純なカテゴリのカスタム オブジェクトに解析する必要がありますか? これにより、アプリケーションもより合理化された感じになります。別の言い方をすれば、コード ビハインドで XML を解析し、それがどのような種類のコンテンツであるかを特定し、独自の「ビデオ」、「画像」、および「テキスト」オブジェクトを設定します。多くの異なる XML 部分を同じオブジェクトに分類できる場合、長期的には、より少ないテンプレート セレクター/データ テンプレートに依存する必要があります。

しかしもちろん、私は多くのことを推測しています。

編集:

  1. 各コントロールに手動で「ビジュアル」スタイルを提供する代わりに、リソース ディクショナリでスタイルを定義し、デフォルトのフォント サイズ、配置、テキスト ラップ設定などをそこに配置します。次に、次のように使用できますStyle="{StaticResource=TextCommentStyle}"
  2. ビデオ/オーディオ/その他のコントロールについては、表示する必要がある項目の種類ごとに 1 つのコンテナーを作成します。異なる項目ごとに、コンテナーとして機能する異なる UserControl を取得する必要があります。
  3. 次に、テンプレート セレクターを使用して、各添付ファイルのタグに応じて必要な UserControl だけを表示できます。それぞれを別の ListItem でホストする必要があると思います。

このアプローチを使用する利点は、コンテナーの数が少なくなり、アプリケーションがテンプレート セレクターを使用してコンテナーを "構成" できるようになることです。ビデオとテキストがある場合、データ テンプレートは、それぞれの UserControls を使用して、ビデオを ListItem に配置し、テキストを別の ListItem に配置する必要があります。ビデオの表示方法を編集する必要がある場合は、1 つのビデオ UserControl を編集するだけで、アプリケーション全体に反映されます。WPF コントロールのスタイルと同じ考え方です。スタイルに設定すると、1 つのファイルでグローバルに変更できます。保守とデバッグがはるかに簡単です。

于 2012-12-23T16:13:15.987 に答える