我有一個列表視圖,我想從中填充對象的幾個字段。最初,我創建了一個數據模板,它引發了一個空白頁面的InvalidOperationException,並且沒有指出異常的原因。我發現在CodeProject上的文章,我有現在的DataTemplate嵌入在二傳手定義:ListView在加載時返回異常
<UserControl x:Class="Servpro.Framework.ViewerModule.Views.MenuView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="580" d:DesignWidth="210">
<UserControl.Resources>
<Style TargetType="ListView">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock
Background="Transparent"
Foreground="Black"
FontSize="12"
Text="{Binding Path=CurrentEvent.EventTypeName, Mode=OneWay}" />
<TextBlock
Background="Transparent"
Foreground="Black"
FontSize="12"
Text="{Binding Path=CurrentEvent.EventMessage, Mode=OneWay}" />
<StackPanel Orientation="Horizontal">
<TextBlock
Background="Transparent"
Foreground="Black"
FontSize="8"
Text="{Binding Path=CurrentEvent.EventLoggedOn, Mode=OneWay}"
Margin="0,0,10,0" />
<TextBlock
Background="Transparent"
Foreground="Black"
FontSize="8"
Text="{Binding Path=CurrentEvent.Program, Mode=OneWay}" />
<TextBlock
Background="Transparent"
Foreground="Black"
FontSize="8"
Text=":" />
<TextBlock
Background="Transparent"
Foreground="Black"
FontSize="8"
Text="{Binding Path=CurrentEvent.Method, Mode=OneWay}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid Margin="4">
<ListView
ItemsSource="{Binding Path=EventList, Mode=OneWay}"
Height="568" VerticalAlignment="Top"
Width="201" HorizontalAlignment="Left"
Margin="4" >
<Border CornerRadius="11" />
<ListView.BorderBrush >
<SolidColorBrush Color="#99FFFFFF" Opacity="0" />
</ListView.BorderBrush>
<ListView.Background>
<SolidColorBrush Color="#99FFFFFF" Opacity="0"/>
</ListView.Background>
</ListView>
</Grid>
隨着定義ASIS我現在得到一個運行時異常,它是在XAML最終指向。但我仍然不明白爲什麼我會得到它。例外情況:
'將值添加到'System.Windows.Controls.ItemCollection'類型的集合引發了一個異常。'行號「55」和行位置「13」。
它的內部異常:
{「操作是無效的,同時的ItemsSource正在使用中訪問和修改元素與ItemsControl.ItemsSource了吧。」}
我清楚在使用ItemsSource爲什麼我得到這個異常?
它拋出什麼錯誤?請把我們正在尋找的錯誤... – Hituptony
錯誤是主題行。在使用ItemSource之前,Items集合必須爲empty。 –