【问题标题】:Parameter count mismatch exception at design time when using itemssource property of raddatagrid使用 raddatagrid 的 itemssource 属性时,在设计时出现参数计数不匹配异常
【发布时间】:2017-02-16 16:23:32
【问题描述】:

我有一个在 Windows 10 中运行的 UWP 项目。在我的 mainpage.xml 中,我有一个 RadDataGrid,我将它绑定到我的视图模型上的一个集合,这在运行时可以正常工作。但是在设计时,我遇到了一个异常,阻止我使用设计器。如果我从 raddatagrid 中删除 ItemsSource,设计器会完美运行,所以我想这与此有关,但我不确定是什么。

非常感谢

XAML sn-ps:

<Page x:Class="UWP.MainPage"    
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
      xmlns:local="using:UWP"
      xmlns:common="using:DataObjects"    
      xmlns:tgrid="using:Telerik.UI.Xaml.Controls.Grid"   
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
      mc:Ignorable="d">

<tgrid:RadDataGrid x:Name="DataGrid" 
                   ItemsSource="{x:Bind Path=ViewModel.Tasks}"
                   Grid.Row="1" Grid.Column="0">                      
</tgrid:RadDataGrid>

型号sn-p:

public ObservableRangeCollection<DataObjects.Task> Tasks { get; }  

堆栈跟踪:

TargetParameterCountException: Parameter count mismatch.

 at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at Telerik.Data.Core.BindingExpressionHelper.<>c__DisplayClass0_0.<CreateGetValueFunc>b__0(Object item)
   at Telerik.Data.Core.Fields.PropertyInfoFieldInfo.GetValue(Object item)
   at Telerik.UI.Xaml.Controls.Grid.DataGridTypedColumn.GetValueForInstance(Object instance)
   at Telerik.UI.Xaml.Controls.Grid.Model.GridModel.Telerik.UI.Xaml.Controls.Grid.ITable.GetCellValue(ItemInfo rowItemInfo, ItemInfo columnItemInfo)
   at Telerik.UI.Xaml.Controls.Grid.CellsController`1.GetCellDecorator(IItemInfoNode parentRow, ItemInfo columnItemInfo, Int32 rowLine, Int32 columnLine)
   at Telerik.UI.Xaml.Controls.Grid.CellsController`1.GenerateCellsForRow(IItemInfoNode rowDecorator, Int32 rowSlot)
   at Telerik.UI.Xaml.Controls.Grid.Model.GridModel.GenerateCellsForReadOnlyRow(Int32 rowSlot, Double largestRowElementWidth, IItemInfoNode rowDecorator)
   at Telerik.UI.Xaml.Controls.Grid.Model.GridModel.Telerik.UI.Xaml.Controls.Grid.ITable.GenerateCellsForRow(Int32 rowSlot, Double largestRowElementHeight, IItemInfoNode rowDecorator)
   at Telerik.UI.Xaml.Controls.Grid.NodePool`2.GenerateCellsForLine(Int32 slot, Double largestLength, T lastElement)
   at Telerik.UI.Xaml.Controls.Grid.NodePool`2.GenerateContainer(IList`1 itemInfos)
   at Telerik.UI.Xaml.Controls.Grid.NodePool`2.MeasureForward(MeasureContext& context)
   at Telerik.UI.Xaml.Controls.Grid.NodePool`2.MeasureVertically(RadSize availableSize, Double offset, Double bufferScale)
   at Telerik.UI.Xaml.Controls.Grid.NodePool`2.OnMeasure(RadSize availableSize, Double offset, Int32 frozenElementsCount, Double verticalBufferScale)
   at Telerik.UI.Xaml.Controls.Grid.Model.GridModel.MeasureCells(RadSize newAvailableSize)
   at Telerik.UI.Xaml.Controls.Grid.RadDataGrid.OnCellsPanelMeasure(RadSize newAvailableSize)
   at Telerik.UI.Xaml.Controls.Grid.Primitives.DataGridCellsPanel.MeasureOverride(Size availableSize)
   at Windows.UI.Xaml.UIElement.Measure(Size availableSize)
   at Telerik.UI.Xaml.Controls.Grid.Primitives.DataGridRootPanel.MeasureOverride(Size availableSize)
   at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)
   at Telerik.UI.Xaml.Controls.RadControl.MeasureOverride(Size availableSize)
   at Windows.UI.Xaml.UIElement.UpdateLayout()

【问题讨论】:

    标签: c# telerik uwp telerik-grid uwp-xaml


    【解决方案1】:

    如果有什么东西会破坏你的 UI,你可以使用这样的东西:

    private static bool? _isInDesignMode;
    
    /// <summary>
    /// Gets a value indicating whether the control is in design mode (running in Blend
    /// or Visual Studio).
    /// </summary>
    public static bool IsInDesignModeStatic
    {
        get
        {
            if (!_isInDesignMode.HasValue)
            {
    #if SILVERLIGHT
                _isInDesignMode = DesignerProperties.IsInDesignTool;
    #else
                var prop = DesignerProperties.IsInDesignModeProperty;
                _isInDesignMode
                    = (bool)DependencyPropertyDescriptor
                    .FromProperty(prop, typeof(FrameworkElement))
                    .Metadata.DefaultValue;
    #endif
            }
    
            return _isInDesignMode.Value;
        }
    }
    

    此属性将保护您的代码,并且不会在设计模式下执行。 您也可以使用 MVVM 库,例如 MVVMLight 或其他东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-17
      • 2018-02-14
      • 1970-01-01
      • 2013-05-22
      相关资源
      最近更新 更多