我应该使用什么控件来显示不同的内容

本文关键字:显示 什么 控件 我应该 | 更新日期: 2023-09-27 18:01:48

我需要在我的Windows Phone应用程序中显示内容。它是文本,图像,音频,视频等。每个Item都有作者姓名和图片,以及List<>内容(不同计数)。我需要展示出来。我现在有一个解决方案-使用TemplateSelectorLisboxLLS。但是内容的组合是>30和30个模板-它大约是2000代码行,我认为这是一个糟糕的解决方案。我试图使通用控制,其中包括所有的容器(控件)的内容,我填充它只有那些内容是在Item(空容器只是最小化),但性能真的很糟糕(每个DataTemplate有10-11个控件)。解决方案与一个控制是好的,但我需要一个良好的性能。有什么办法可以解决这个问题吗?

我应该使用什么控件来显示不同的内容

我在Windows Phone上显示不同的图钉时也遇到了同样的问题。我做了一个usercontrol并在code-behind中设置了一个特定的Template:

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中定义

相关文章: