我有listBox和ObservableCollection。 listBox.ItemSource(listNotify.ItemSource)被設置爲該ObservableCollection(errosList)。 我的問題是,我不知道如何從錯誤列表中刪除正確的元素,當用戶點擊列表框中的內容x的按鈕。對於listBox的項目,我使用ItemTemplate,在一個stackPanel和一個stackPanel中,我有一個按鈕。 婁是XAML代碼:如何從列表框和ObservableCollection中刪除自定義項,點擊按鈕
<ListBox x:Name="listNotify">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="35">
<Image Height="16" Source="/Template;component/Resources/error.png" Stretch="Fill" VerticalAlignment="Top" Width="16"/>
<StackPanel Orientation="Vertical">
<HyperlinkButton Content="{Binding ErrorHeader}" HorizontalAlignment="Left" Height="16" Width="125"/>
<TextBlock Text="{Binding ErrorMessage}" HorizontalAlignment="Left" Width="405" d:LayoutOverrides="VerticalAlignment" />
</StackPanel>
<Button Content="x" Width="20" Height="20" Click="removeError_Click"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
的代碼是從一個Silverlight 4項目。 謝謝。
這個工作,我決心問題。 謝謝HCL。 – tribanp 2010-08-07 09:25:53