我有一个装满物品的SL4 ListBox。这是ItemContainerStyle:
<Style x:Key="DataItemStyle"
TargetType="ListBoxItem">
<Setter Property="Background"
Value="Transparent" />
<Setter Property="TabNavigation"
Value="Local" />
<Setter Property="HorizontalContentAlignment"
Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid Background="{TemplateBinding Background}"
LLamasoft:DragDropBehaviors.DragDropManager="{Binding ScratchPad.TableExplorer.DragDropManager, Source={StaticResource ViewModels}}"
LLamasoft:DragDropBehaviors.DragSourceEffect="Copy">
<ToolTipService.ToolTip>
<c1:C1DataGrid ItemsSource="{Binding Preview}"
CanUserAddRows="False"
CanUserEditRows="False"
LLamasoft:DataGridBehaviors.FilterIdentityColumn="true" />
</ToolTipService.ToolTip>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation Duration="0"
To=".35"
Storyboard.TargetProperty="Opacity"
Storyboard.TargetName="fillColor" />
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Duration="0"
To=".55"
Storyboard.TargetProperty="Opacity"
Storyboard.TargetName="contentPresenter" />
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected" />
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimation Duration="0"
To=".75"
Storyboard.TargetProperty="Opacity"
Storyboard.TargetName="fillColor2" />
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0"
Storyboard.TargetProperty="Visibility"
Storyboard.TargetName="FocusVisualElement">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unfocused" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="fillColor"
Fill="#FFBADDE9"
IsHitTestVisible="False"
Opacity="0"
RadiusY="1"
RadiusX="1" />
<Rectangle x:Name="fillColor2"
Fill="#FFBADDE9"
IsHitTestVisible="False"
Opacity="0"
RadiusY="1"
RadiusX="1" />
<Grid Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<SaaS_icons:document_table Margin="4"
Height="40"
Grid.Column="1" />
<ContentPresenter x:Name="contentPresenter"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{Binding Name}"
Grid.Row="1"
Grid.ColumnSpan="3"
HorizontalAlignment="Center" />
</Grid>
<Rectangle x:Name="FocusVisualElement"
RadiusY="1"
RadiusX="1"
Stroke="#FF6DBDD1"
StrokeThickness="1"
Visibility="Collapsed" />
<c1:C1ContextMenuService.ContextMenu>
<c1:C1ContextMenu>
<c1:C1MenuItem Header="Edit Info"
Command="{Binding ScratchPad.TableExplorer.EditInfoCommand, Source={StaticResource ViewModels}}"
CommandParameter="{TemplateBinding DataContext}" />
<c1:C1MenuItem Header="Geocode"
Command="{Binding ScratchPad.TableExplorer.GeocodeTableCommand, Source={StaticResource ViewModels}}"
CommandParameter="{TemplateBinding DataContext}" />
<c1:C1MenuItem Header="Delete"
Command="{Binding ScratchPad.TableExplorer.DeleteCommand, Source={StaticResource ViewModels}}"
CommandParameter="{TemplateBinding DataContext}" />
</c1:C1ContextMenu>
</c1:C1ContextMenuService.ContextMenu>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
ItemsSource设置为VM中的ObservableCollection。如图所示,有一个上下文菜单选项可以从列表中删除项目。我可以整天添加和删除项目,没有任何问题,直到删除最后一项。然后我收到错误:
价值不在预期范围内
我看到大多数人称模板中的x:Name元素是一个问题,但我没有看到任何问题,当我只删除最后一个问题时,我感到非常困惑。谁能帮我吗?这就是调用堆栈中的所有内容:
System.Windows.dll!MS.Internal.Error.CallApplicationUEHandler(System.Exception e) + 0x4d bytes
System.Windows.dll!MS.Internal.Error.CallAUEHandler(uint hr, out uint bIsHandled = 0) + 0x14 bytes
[Appdomain Transition]