值不在Telerik RadGridView中的预期范围错误绑定范围内

时间:2014-06-17 00:53:05

标签: silverlight telerik radgridview

我正在关注Telerik发布的关于如何在RadGridView控件中显示/隐藏列的示例,如下所示:

  <StackPanel x:Name="CustomizeGrid" Background="Transparent" Orientation="Horizontal">
    <ListBox ItemsSource="{Binding Columns, ElementName=WorklistGridView}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <CheckBox Content="{Binding Header}" IsChecked="{Binding IsVisible, Mode=TwoWay}" />
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    <telerik:RadGridView x:Name="WorklistGridView" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed" IsReadOnly="True" SelectionMode="Multiple" 
                     CanUserSelect="False" IsSynchronizedWithCurrentItem="False" ItemsSource="{Binding Mode=OneWay}" IsFilteringAllowed="True">
        <telerik:RadGridView.Columns>
            <telerik:GridViewSelectColumn x:Name="Select" IsResizable="False" />
            <telerik:GridViewDataColumn Header="Status" DataMemberBinding="{Binding OrderStatusDescription}"/>
            <telerik:GridViewDataColumn Header="Patient Name" DataMemberBinding="{Binding PatientName}"/>

但该示例未正确编译。问题在于:CheckBox`Content =“{Binding Header}”列出的主要错误是:值不在预期范围内。

我不确定为什么会这样。我将尝试发布下面的其余错误。有没有其他人有这个工作,或有任何想法是什么?

System.InvalidOperationException

尝试在设计图面上渲染当前的silverlight项目时遇到未处理的异常。要诊断此故障,请尝试使用silverlight开发人员运行时在常规浏览器中运行项目。在

Microsoft.Windows.Design.Platform.SilverlightViewProducer.OnUnhandledException(Object sender, ViewUnhandledExceptionEventArgs e) at Microsoft.Expression.Platform.Silverlight.SilverlightPlatformSpecificView.OnUnhandledException(Object sender, ViewUnhandledExceptionEventArgs args) at Microsoft.Expression.Platform.Silverlight.Host.SilverlightImageHost.<>c_DisplayClass1.b_0(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

System.ArgumentException Value does not fall within the expected range. at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh) at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj) at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value) at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue) at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation) at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp) at System.Windows.Data.BindingExpression.SendDataToTarget() at System.Windows.Data.BindingExpression.SourceAcquired() at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e) at System.Windows.Data.BindingExpression.DataContextChanged(Object sender, DataContextChangedEventArgs e) at System.Windows.DataContextChangedEventHandler.Invoke(Object sender, DataContextChangedEventArgs e) at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e) at System.Windows.FrameworkElement.OnTreeParentUpdated(DependencyObject newParent, Boolean bIsNewParentAlive) at System.Windows.DependencyObject.UpdateTreeParent(IManagedPeer oldParent, IManagedPeer newParent, Boolean bIsNewParentAlive, Boolean keepReferenceToParent) at MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(IntPtr oldParentElement, IntPtr parentElement, IntPtr childElement, Byte bIsParentAlive, Byte bKeepReferenceToParent, Byte bCanCreateParent)

1 个答案:

答案 0 :(得分:1)

我设法复制了你的问题,但我收到了不同的例外(&#34; Element已经是另一个元素的孩子&#34;)。我认为原因可以是相同的,所以看看它是否有帮助。

稍微调试显示,当SelectionMode设置为Multiple时,Header的{​​{1}}变为GridViewSelectColumn。这意味着您正在尝试将同一个CheckBox添加到CheckBox内的列标题和CheckBox内容中。只需尝试删除ListBox,看看是否有同样的问题。

如果是这种情况,那么您可以通过向仅传递字符串的SelectionMode绑定添加转换器来解决问题。例如:

CheckBox.Content

然后在XAML中:

public class HeaderConverter : IValueConverter
{
  public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  {
     if (value is string)
        return value;

     return string.Empty;
  }

  public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  {
     throw new NotImplementedException();
  }
}