我ObservableCollection
在 ViewModel 中有一个静态 MarketList,它以Table
下列方式绑定:
<FlowDocumentScrollViewer Height="216" VerticalAlignment="Top" Margin="-7,2,7,0" >
<FlowDocument>
<Table CellSpacing="0" Name="MBPTable" >
<Table.DataContext>
<MultiBinding UpdateSourceTrigger="Explicit" Mode="TwoWay" Converter="{StaticResource indexerConverter}">
<Binding Path="MarketList" UpdateSourceTrigger="PropertyChanged" NotifyOnSourceUpdated="True" Mode="TwoWay" BindsDirectlyToSource="True" />
<Binding Path="MBPindex" Mode="TwoWay" />
</MultiBinding>
</Table.DataContext>
<Table.Resources>
<local:IndexerConverter x:Key="indexerConverter"></local:IndexerConverter>
</Table.Resources>
Table
包含ListView
绑定到 MarketList 的属性。
<ListView Name="MarketByPriceList" Width="300" ItemsSource="{Binding MarketByPriceList, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" AlternationCount="2" Margin="0,15,0,0" >
<ListView.View>
<GridView>
<GridViewColumn Header="Orders" Width="48" DisplayMemberBinding="{Binding MBP_NoofBuy_Orders, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" ></GridViewColumn>
<GridViewColumn Header="Bid Qty" Width="48" DisplayMemberBinding="{Binding MBPBID_Qty, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" ></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
这是转换器方法
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values != null && values[0] != DependencyProperty.UnsetValue)
{
// ObservableCollection<GlobalItems.Model.MarketWatchModel> allNames = (ObservableCollection<GlobalItems.Model.MarketWatchModel>)values[0];
int index = (int)values[1];
return GlobalItems.ViewModel.MarketWatchModelView.MarketList[index];
}
else
{
return null;
}
}
绑定工作正常,但集合中的更新未反映在 UI 中