【发布时间】:2014-01-22 07:08:33
【问题描述】:
我有显示发票项目的列表框:
<ListBox x:Name="lbInvoice" ItemsSource="{Binding ocItemsinInvoice}" Margin="10,27,0,143" Width="412" HorizontalAlignment="Left" BorderBrush="{x:Null}">
<ListBox.ItemTemplate>
<DataTemplate>
<ToggleButton x:Name="btnInvoiceItem" Checked="btnInvoiceItem_Checked" Style="{StaticResource InvoiceBG}" TabIndex="{Binding ItemsinInvoiceID}" Padding="20,0,0,0" FontSize="12" Width="408" Height="35" Foreground="#FFcfcfcf" IsChecked="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}" BorderThickness="1,0.5">
<ToggleButton.BorderBrush>
<SolidColorBrush Color="#FF5B616F" Opacity="0.7"/>
</ToggleButton.BorderBrush>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Item.ItemName}" Width="200"/>
<TextBlock Text="{Binding SalePrice}" Width="50"/>
<TextBlock Text="{Binding Quantity,NotifyOnSourceUpdated=True}" Width="50"/>
<TextBlock Text="{Binding Total}" Width="50"/>
</StackPanel>
</ToggleButton>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
问题是当我在后面的代码中更改数量值时(例如点击事件)
ItemsinInvoice _lbi = (ItemsinInvoice)lbInvoice.SelectedItem;
_lbi.Quantity = 99; //for example
屏幕上列表中数量的值没有改变,我错过了什么吗。
谢谢
【问题讨论】:
-
ItemsinInvoice.Quantity属性是什么样的?你实现INotifyPropertyChanged接口了吗? -
如何实现 INotifyPropertyChanged 接口?
-
这个链接会帮助你 - How to implement INPC.
标签: c# wpf listbox observablecollection