私のアプリケーションでは、現在非常によく似た2つのリストボックスが機能しています。問題は、一方が適切に動作し、他方が正しく動作しないことです。問題を表示する1は、このいずれかになります。多角形を含むSilverlightリストボックス - スクロール時の例外と失敗
<ListBox Grid.Row="2" Margin="0,35,10,5" Name="shapeEncodingListBox" HorizontalAlignment="Right" Width="225" Style="{StaticResource EncodingListBoxStyle}" BindingValidationError="shapeEncodingListBox_BindingValidationError">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="Show Items" Click="MenuItem_Click" />
<toolkit:MenuItem Header="Hide Items" Click="MenuItem_Click_1"/>
<toolkit:Separator/>
<toolkit:MenuItem Header="Isolate Items" Click="MenuItem_Click_2" />
<toolkit:Separator/>
<toolkit:MenuItem Header="Select Items" Click="MenuItem_Click_3" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Style="{StaticResource EncodingListBoxItemPanelStyle}">
<Polygon Points="{Binding Shape}" Style="{StaticResource EncodingListBoxItemShapeIndicatorStyle}"/>
<TextBlock x:Name="encodeShapePanelLegend" Text="{Binding Name}" Style="{StaticResource EncodingListBoxItemTextStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
このListboxsのItemsSourceは、このクラスのオブジェクトののObservableCollectionにバインドされた2つのリストボックス間の差が働い1であることである
public class ShapeEncoding
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private PointCollection shape;
public PointCollection Shape
{
get { return shape; }
set { shape = value;}
}
private int index;
public int Index
{
get { return index; }
set { index = value; }
}
public ShapeEncoding(string n, Polygon p, int i)
{
name = n;
shape = new PointCollection();
foreach (Point pt in p.Points)
{
shape.Add(new Point(pt.X, pt.Y));
}
index = i;
}
}
Color-Propertyにバインドされ、誤ったものはPointCollection-Propertyにバインドされます。
ListBoxは、PointCollectionを正しく初期化し、ポリゴンは意図したとおりに表示されます。ただし、ListBoxをスクロールダウンしてから再び上に移動すると、以前に表示されなかったアイテムは表示されず、表示されない各アイテムに対してエラーが生成されます。 エラーとスタックトレースは次のとおりです。
値が予期された範囲内にありません。 MS.Internal.XcpImports.SetValue(IManagedPeerBaseのDOH、たDependencyPropertyプロパティでMS.Internal.XcpImports.SetValue(IManagedPeerBase OBJ、たDependencyPropertyプロパティ、のDependencyObjectのDOH) でMS.Internal.XcpImports.CheckHResult(UInt32型のHR) で
System.Windows.DependencyObject.UpdateEffectiveValueでSystem.Windows.DependencyObject.SetObjectValueToCore(DPたDependencyProperty、OBJECT>値)で、オブジェクトobj) System.Windows.DependencyObject.SetEffectiveValueで (たDependencyPropertyプロパティ、EffectiveValueEntry & newEntry、newValueにオブジェクト) (DependencyPropertyプロパティ、EffectiveValueEntry oldEntry、EffectiveValueEntry & newEntry、ValueOperationオペレーションSystem.Windows.Data.BindingExpressionでSystem.Windows.Data.BindingExpression.SourceAcquiredでSystem.Windows.Data.BindingExpression.SendDataToTargetでSystem.Windows.DependencyObject.RefreshExpression(たDependencyProperty DP) (AT N) ) () System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)にSystem.Windows.Data.BindingExpression.DataContextChanged(オブジェクト送信者、DataContextChangedEventArgs E) で.System.Windows.IDataContextChangedListener.OnDataCont> extChanged(オブジェクト送信者、DataContextChangedEventArgs E) でSystem.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e) でSystem.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdateでSystem.Windows.DependencyObject.UpdateTreeParent(IManagedPeer oldParent、IManagedPeer新規の親、ブールbIsNewParentAlive、ブールkeepReferenceToParent) でSystem.Windows.FrameworkElement.OnTreeParentUpdated(新規の親のDependencyObject、ブールbIsNewParentAlive) (のIntPtr oldParentElementで、のIntPtr> parentElement、のIntPtr childElement、バイトbIsParentAlive、バイトbKeepReferenceToParent、バイト> bCanCreateParent)
私は何が起こっているかのように疑いを持っています。このアプリケーションを作成する過程で、SilverlightのPointCollectionsがPolygons間で共有できないことを認識しました。リストボックスが視野のないアイテムをフェッチしているときに、同じPointCollectionを持つリスト内に新しいアイテムを作成しようとすると、エラーと失敗が発生する可能性はありますか?
これが当てはまる場合、私はそれを解決する最良の方法が何であるかはわかりません。それは、最初の場所で項目をフェッチすることからListBoxを維持する方法はありますか?