0

我正在更新一个透视查看器应用程序并遇到了以下问题。希望有人会在我被卡住时给出答案。

问题:加载页面时,具有属性和其他功能的一侧加载正常,但交易卡不加载任何图像。其中一些加载默认的白色背景,而大多数显示深灰色,几乎是黑色的背景。所有这些都可以放大并显示所有属性,但没有图像。

调试:我发现注释掉一些属性会导致图像每次都正确加载。如果我只注释掉 1 或 2 则图像将在某些时候加载(大约 10 次页面刷新中的 2 次)。目前,列表中包含 29 个属性,数据正在从数据库中加载,然后在 pivotviewer.ItemsSource 中使用。

有任何想法吗?

有一些名称更改的代码(选项二之一是我要注释掉的属性):

MainPage.xaml.cs

public MainPage()
    {
       InitializeComponent();

       PivotViewModel pivotModel = new PivotViewModel();
       CollectionsComboBox.SelectedIndex = 0;
       this.DataContext = pivotModel;
    }

    private void DropDown_ItemSelected(object sender, EventArgs e)
    {
        // Process selected index change here
        if (((ComboBox)sender).SelectedValue == "Option One")
        {
            OptionOnePivotViewModel OptionOnePivot = new OptionOnePivotViewModel();
            PivotViewer.ItemsSource = OptionOnePivot.Data;
            PivotViewer.PivotProperties = OptionOnePivot.PivotProperties;
            PivotViewer.ItemTemplates = OptionOnePivot.TemplateCollection;
            PivotViewer.ItemAdornerStyle = blankAdorner;  
        }
        else
        {
            OptionTwoPivotViewModel OptionTwoPivot = new OptionTwoPivotViewModel();
            PivotViewer.ItemsSource = OptionTwoPivot.Data;
            PivotViewer.PivotProperties = OptionTwoPivot.PivotProperties;
            PivotViewer.ItemAdornerStyle = basicAdorner;
            PivotViewer.ItemTemplates = OptionTwoPivot.TemplateCollection;
        }
    }

OptionTwoPivotViewModel.cs:

public OptionTwoPivotViewModel()
        {
            DomainContext = new OptionTwoDomainContext();
            Data = DomainContext.Load(DomainContext.GetHRDatasQuery()).Entities;
            PivotProperties = getPivotProperties();
            SmallTemplate = "EmpSmall";

            TemplateCollection = new PivotViewerItemTemplateCollection()
                 {
                 (PivotViewerItemTemplate)  Application.Current.Resources[SmallTemplate]
                 };
        }

        private List<PivotViewerProperty> getPivotProperties()
        {
            List<PivotViewerProperty> properties = new List<PivotViewerProperty>
            {
                new PivotViewerStringProperty{ Id="Name", Options=PivotViewerPropertyOptions.CanSearchText, DisplayName="Name", Binding=new System.Windows.Data.Binding("Name")},
                new PivotViewerStringProperty{ Id="Status", Options=PivotViewerPropertyOptions.CanFilter, DisplayName="Status", Binding=new System.Windows.Data.Binding("Status")},
                new PivotViewerDateTimeProperty{ Id="StartDate", Options=PivotViewerPropertyOptions.CanFilter, DisplayName="Start Date", Binding=new System.Windows.Data.Binding("StartDate")},
                //additional properties follow...
         };
            return properties;

编辑:我注意到,如果我在以下属性获取器中设置断点,然后继续图像也加载正常。

public ImageSource BackgroundImage
        {
            get
            {
                string location = Image_Location;
                location = location.Substring(location.LastIndexOf("/"));
                Uri uri;

                if (Image_Location.Contains(".gif"))
                {
                    uri = new Uri(Image_Location, UriKind.Absolute);
                }
                else
                {
                    var host = Application.Current.Host.Source.Host;
                    uri = new Uri("https://" + host + "/fileLibrary/employees/images/500"+location, UriKind.RelativeOrAbsolute);
                }

                // set the image source 
                BitmapImage bmpImg = new BitmapImage(uri);
                _loaded = _backgroundImage != null;
                if (!_loaded)
                {
                    bmpImg.ImageOpened += ImageOpened;
                    bmpImg.ImageFailed += ImageFailed;
                }
                return new BitmapImage(uri);
            } 
4

1 回答 1

0
       TemplateCollection = new PivotViewerItemTemplateCollection()
             {
             (PivotViewerItemTemplate)  Application.Current.Resources[SmallTemplate]
             };

没有在上面的初始化程序中分配属性?

于 2014-10-13T04:33:51.680 回答