0

Windows Phone アプリケーションでコンテンツを表示する必要があります。テキスト、画像、オーディオ、ビデオなどです。それぞれItemに著者名と画像、およびList<>コンテンツ (カウントが異なります) があります。そして、私はそれを示す必要があります。私が今持っている解決策は 1 つあります。 or で使用しTemplateSelectorます。しかし、コンテンツの組み合わせは 30 を超え、テンプレートは 30 です。これは約 2000 のコード行であり、悪い解決策だと思います。コンテンツのすべてのコンテナー (コントロール) を含むユニバーサル コントロールを作成しようとしましたが、(最小化された空のコンテナー) にあるコンテンツのみを入力しましたが、パフォーマンスは非常に悪いです (それぞれに 10 ~ 11 個のコントロールがあります)。コントロールが 1 つのソリューションは優れていますが、優れたパフォーマンスが必要です。この問題を解決する方法はありますか?LisboxLLSItemDataTemplate

4

1 に答える 1

0

Windows Phone で別の画鋲を表示するという同じ問題がありました。私はユーザーコントロールを行い、コードビハインドで特定のテンプレートを設定しました:

public partial class Map : UserControl
{
    public Map()
    {
        InitializeComponent();
        this.Loaded += Map_Loaded;
    }

    void Map_Loaded(object sender, RoutedEventArgs e)
    {
        (this.DataContext as MyViewModel).LoadingItemsCompleted += OnLoadingItemsCompleted;
    }

    private void OnLoadingItemsCompleted(object sender, EventArgs eventArgs)
    {
        // Don't care about thats
        ObservableCollection<DependencyObject> children = Microsoft.Phone.Maps.Toolkit.MapExtensions.GetChildren(map);
        MapItemsControl itemsControl = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;

        // Here !
        foreach (GeolocalizableModel item in (this.DataContext as MyViewModel).Items)
        {
            Pushpin pushpin = new Pushpin();
            switch (item.PushpinTemplate)
            {
                case Server.PushpinTemplate.First:
                    pushpin.Template = this.Resources["firstPushpinTemplate"] as ControlTemplate;
                    break;
                case Server.PushpinTemplate.Second:
                    pushpin.Template = this.Resources["secondPushpinTemplate"] as ControlTemplate;
                    break;
                case Server.PushpinTemplate.Third:
                    pushpin.Template = this.Resources["thirdPushpinTemplate"] as ControlTemplate;
                    break;
                default:
                    if (PushpinTemplate != null) pushpin.Template = PushpinTemplate;
                    break;
            }

            pushpin.Content = item.PushpinContent;
            pushpin.GeoCoordinate = item.Location;
            itemsControl.Items.Add(pushpin);
        }
    }

    public ControlTemplate PushpinTemplate
    {
        get { return (ControlTemplate)GetValue(PushpinTemplateProperty); }
        set { SetValue(PushpinTemplateProperty, value); }
    }

    // Using a DependencyProperty as the backing store for PushpinTemplate.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty PushpinTemplateProperty =
        DependencyProperty.Register("PushpinTemplate", typeof(ControlTemplate), typeof(Map), new PropertyMetadata(null));
}

テンプレートは UserControl で定義されます。

于 2013-03-04T09:46:07.003 に答える