开发者

Need simple help to develop c# algorithm

I'm using WPF. On my window there is a data开发者_如何学C grid which binding with observable collection. This collection contains data about room check outs. So there is also one window which must add service collection to data grid >> create new collection with name of service an fill cell with price.

This price must be set on row where id(column) == "example". I think it must be very easy but I'm trying this 2 days.. so my question : is it possible to bind data grid with two collections?

How I can add collection new property ? Like that : public string ServiceName{get;set;} from another window.

Please advice some good thing how to solve this problem


To bind to multiple collections use the CompositeCollection.

Here's a ListBox example:

<ListBox Name="myListBox" Height="300" Width="200" Background="White">
  <ListBox.ItemsSource>
    <CompositeCollection>
      <CollectionContainer
        Collection="{Binding Source={StaticResource GreekGodsData}}" />
      <CollectionContainer
        Collection="{Binding Source={StaticResource GreekHeroesData}}" />
      <ListBoxItem Foreground="Red">Other Listbox Item 1</ListBoxItem>
      <ListBoxItem Foreground="Red">Other Listbox Item 2</ListBoxItem>
    </CompositeCollection>
  </ListBox.ItemsSource>
</ListBox>

This example and more info can be found on MSDN: http://msdn.microsoft.com/en-us/library/system.windows.data.compositecollection.aspx.

Another important point to mention is CompositeCollection does not implement IEditableCollectionView so if you need to edit the datagrid, you cannot use CompositeCollection without implementing IEditableCollectionView yourself.


No you can't bind a property to two things at the same time. Normaly you would aggregate the two data-objects into a single Helperobject and use those in the observable-collection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜