我試圖以編程方式將UIElement
s添加到LongListSelector
項目。我創建模板頁眉,頁腳,項目等WP7:將UIElements動態添加到LongListSelector項目
現在我做這樣的事情(列表項模板):
<DataTemplate x:Key="listItemTemplate">
<ContentPresenter Content="{Binding ItemContent}"></ContentPresenter>
</DataTemplate>
模型裏面,我assisgn的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]
ItemContent內部是什麼?它是什麼類型? @Spiri – 2012-08-13 17:12:52
我嘗試了一個Grid,一個StackPanel,甚至帶有一個帶有Grid子元素的邊框 - 當我在LongListSelector內添加了很多項時仍然有異常 – Spiri 2012-08-13 20:48:39
否@Spiri。您將ContentPresenter的內容綁定到ItemContent。該屬性(ItemContent)中保存了什麼? – 2012-08-14 07:03:00