我正在使用列表框来显示项目列表,下面给出了它的 XAML 代码,
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="List" HorizontalAlignment="Left" Height="612" Margin="6,7,0,0" VerticalAlignment="Top" Width="443" SelectionChanged="List_SelectionChanged_1">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Width="400" Height="50">
<TextBlock x:Name="tbName" Width="400" Height="44" FontSize="22" FontWeight="Bold" Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
我只是通过以下 C# 代码填充列表,
foreach (var item in categoryDetails.Category)
{
CategoryDisplay data = new CategoryDisplay();
data.Name = item.accountName;
data.Id = item.accountID;
this.List.Items.Add(data);
}
一切都很顺利,直到最后一步,当
this.List.Items.Add(data);
执行时,会出现一个错误,指出,
An exception of type 'System.UnauthorizedAccessException' occurred in System.Windows.ni.dll but was not handled in user code
可能是什么问题呢?我应该怎么做才能纠正它?