我有一个 DataGrid 绑定到一个名为 Quote 的对象
<CollectionViewSource x:Key="cvs" Source="{Binding QuoteList}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="TimeStamp" Direction="Descending"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
......
<DataGrid ItemsSource="{Binding Source={StaticResource cvs}}" x:Name="MasterAllGrid" AutoGenerateColumns="False"
HeadersVisibility="All" CanUserAddRows="False"
VerticalAlignment="Stretch" SelectionChanged="MasterAllGrid_SelectionChanged" VerticalScrollBarVisibility="Auto" >
<DataGrid.Columns>
<DataGridTextColumn Header="ticker" Binding="{Binding Path=Ticker}"/>
<DataGridTextColumn Header="name" Binding="{Binding Path=ProductName}"/>
<DataGridTextColumn Header="tenor" Binding="{Binding Path=Tenor}"/>
<DataGridTextColumn Header="rating" Binding="{Binding Path=Rating}"/>
<DataGridTextColumn Header="Bid Amount" Binding="{Binding Path=BidAmount}"/>
<DataGridTextColumn Header="Bid Price" Binding="{Binding Path=BidPrice}"/>
<DataGridTextColumn Header="Offer Price" Binding="{Binding Path=OfferPrice}"/>
<DataGridTextColumn Header="Offer Amount" Binding="{Binding Path=OfferAmount}"/>
<DataGridTextColumn Header="Price" Binding="{Binding Path=Price}"/>
<DataGridTextColumn Header="Amount" Binding="{Binding Path=Amount}"/>
<DataGridTextColumn Header="Direction" Binding="{Binding Path=Direction}"/>
<DataGridTextColumn Header="Action" Binding="{Binding Path=Action}"/>
<DataGridTextColumn Header="Time" Binding="{Binding Path=TimeStamp}"/>
<DataGridTextColumn Header="Sender" Binding="{Binding Path=Sender.SuojiContactWrapper.SuojiContact.FullName}"/>
</DataGrid.Columns>
</DataGrid>
我试图将选定的行回退到引用
Quote quote = (Quote)MasterAllGrid.SelectedItem;
但是,似乎因为 Sender 我必须使用嵌套属性,
<DataGridTextColumn Header="Sender" Binding="{Binding Path=Sender.SuojiContactWrapper.SuojiContact.FullName}"/>
强制转换在 Quote 对象中具有 Sender 属性为 Null。
我可以知道如何解决这个问题吗?