“BindingExpression path error” using ItemsControl and VirtualizingStackPanel

后端 未结 2 1996
时光取名叫无心
时光取名叫无心 2021-02-06 19:03

I\'m using Silverlight on Windows Phone 7.

Is it normal to get loads of \"BindingExpression path error\" debug messages when using a VirtualizingStackPanel? I think it

2条回答
  •  深忆病人
    2021-02-06 19:28

    I know this post is pretty old, but a solution without creating the dummy properties is making sure the DataContext of the items can only be of the type you expect.

    I do this with the following converter on the root of the data template:

    public class SpecificTypeConverter : IValueConverter
    {
        public string Type { get; set; }
    
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || value.GetType().FullName == this.Type)
            {
                return value;
            }
    
            return DependencyProperty.UnsetValue;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    Add a static resource like this:

    
         
    
    

    And in the data template, use the converter:

    
        
            
        
    
    

    Now the Name property of the parent will never be checked.

提交回复
热议问题