我正在尝试以编程方式将UIElement
s 添加到LongListSelector
项目中。我已经为页眉、页脚、项目等创建了模板。
现在我正在做这样的事情(列表项模板):
<DataTemplate x:Key="listItemTemplate">
<ContentPresenter Content="{Binding ItemContent}"></ContentPresenter>
</DataTemplate>
在模型内部,我将 ItemContent 分配给一个网格,在该网格上添加不同的 UI 元素。我真的不知道这是否是这样做的方法,或者这是否可能在 LongListSelector 上但滚动列表时我得到一个“参数不正确”。异常(起初,一切似乎都很好,添加的所有元素看起来都很好)。我尝试了不同的方法,但都没有奏效,我觉得我只是在没有特定想法的情况下随机尝试解决方案。有没有人设法通过使用 LongListSelector 做到这一点(任何建议将不胜感激)?
调用堆栈:
LongListSelectorPOC.dll!LongListSelectorPOC.App.Application_UnhandledException(object sender, System.Windows.ApplicationUnhandledExceptionEventArgs e) Line 102 + 0x5 bytes C#
System.Windows.dll!MS.Internal.Error.CallApplicationUEHandler(System.Exception e) + 0x30 bytes
System.Windows.dll!MS.Internal.Error.GetXresultForUserException(System.Exception ex) + 0x4d bytes
System.Windows.dll!MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(System.IntPtr oldParentElement, System.IntPtr parentElement, System.IntPtr childElement, byte bIsParentAlive, byte bKeepReferenceToParent, byte bCanCreateParent) + 0x6b bytes
[External Code]
System.Windows.dll!MS.Internal.XcpImports.MeasureOverrideNative(System.IntPtr element, float inWidth, float inHeight, out float outWidth, out float outHeight)
System.Windows.dll!MS.Internal.XcpImports.FrameworkElement_MeasureOverride(System.Windows.FrameworkElement element, System.Windows.Size availableSize) + 0x26 bytes
System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.Windows.Size availableSize) + 0x7 bytes
System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, double inWidth, double inHeight, out double outWidth, out double outHeight) + 0x43 bytes
[External Code]
System.Windows.dll!MS.Internal.XcpImports.Measure_WithDesiredSizeNative(System.IntPtr element, float inWidth, float inHeight, out float outWidth, out float outHeight)
System.Windows.dll!MS.Internal.XcpImports.UIElement_Measure_WithDesiredSize(System.Windows.UIElement element, System.Windows.Size availableSize) + 0x26 bytes
System.Windows.dll!System.Windows.UIElement.Measure_WithDesiredSize(System.Windows.Size availableSize) + 0x39 bytes
System.Windows.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureChild(System.Windows.UIElement child, System.Windows.Size layoutSlotSize) + 0x42 bytes
System.Windows.dll!System.Windows.Controls.VirtualizingStackPanel.GeneratePreviousChild(int childIndex, System.Windows.Size layoutSlotSize) + 0x6f bytes
System.Windows.dll!System.Windows.Controls.VirtualizingStackPanel.GeneratePreviousItems(ref double logicalVisibleSpace, ref System.Windows.Size stackDesiredSize, System.Windows.Size layoutSlotSize, bool isHorizontal, bool adjustPositions) + 0x138 bytes
System.Windows.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(System.Windows.Size constraint) + 0x4e1 bytes
System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, double inWidth, double inHeight, out double outWidth, out double outHeight) + 0x43 bytes
[External Code]