簡體   English   中英

WPF錯誤:“ System.Windows.Markup.XamlParseException:'DataGridRow'TargetType與元素'GridRowContent'的類型不匹配。”

[英]WPF error: “System.Windows.Markup.XamlParseException: 'DataGridRow' TargetType does not match type of element 'GridRowContent'.”

該問題/答案對的類型為“分享您的知識,問答式”,旨在將此錯誤與最可能的原因聯系起來。

我希望將來對某些開發人員有用。

錯誤:

System.Windows.Markup.XamlParseException: 'DataGridRow' TargetType does not match type of element 'GridRowContent'. ---> System.InvalidOperationException: 'DataGridRow' TargetType does not match type of element 'GridRowContent'.
        at System.Windows.Style.CheckTargetType(Object element)
        at System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle, Style& styleCache)
        at System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
        at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
        at System.Windows.StyleHelper.ApplyTemplatedParentValue(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, DependencyProperty dp, FrameworkElementFactory templateRoot)
        at System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, Boolean isDetach, FrameworkElementFactory templateRoot)
        at System.Windows.FrameworkTemplate.InvalidatePropertiesOnTemplate(DependencyObject container, Object currentObject)
        at System.Windows.FrameworkTemplate.HandleBeforeProperties(Object createdObject, DependencyObject& rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
        at System.Windows.FrameworkTemplate.<>c__DisplayClass6.<LoadOptimizedTemplateContent>b__3(Object sender, XamlObjectEventArgs args)

當我遇到此特定錯誤時,根本原因是網格內的樣式不兼容。

例如,如果您在網格中看到以下代碼片段:

<grid:GridControl.View>
     <grid:TableView x:Name="tableView"
         VerticalScrollbarVisibility="Auto"
         DetailHeaderContent="Notification Tasks"
         AutoWidth="True"
         NavigationStyle="Row"
         RowStyle="{StaticResource MyStyle}"
         ShowGroupPanel="False"
         FadeSelectionOnLostFocus="False"
         ShowIndicator="False"
         >
     </grid:TableView>
</grid:GridControl.View>

然后,該錯誤與與RowStyle有關的行有關。 指向的RowStyle找不到,或者此網格的類型錯誤。 當WPF搜索可視化樹時,它在嘗試應用樣式時會遇到異常。

如果錯誤已說出是哪一行真正導致了錯誤,那么錯誤將更加清楚,而不僅僅是暗示網格的每一行中似乎都存在問題。

如果您使用的是Visual Studio 2013 + ReSharper,它將用藍色花體在下划線的行下划線,指示錯誤的來源。 作為記錄,我與ReSharper沒有任何關系,並且還有許多其他出色的解決方案可以完成完全相同的工作,例如CodeRush,Visual Studio 2015等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM