Click here to Skip to main content
15,918,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a newbie in WPF
As mention I have property in class

public ObservableCollection<Company> GetCompany
            return _collectionCompany;

How can I access it in XAML?
I am trying like this:

<DataGridComboBoxColumn Header="Company" ItemsSource="{StaticResource GetCompany}"  Width="200"></DataGridComboBoxColumn>

But it gives an error.
Updated 12-Jan-11 23:17pm
Tarun.K.S 13-Jan-11 4:58am    
ItemSource might be at the wrong place. how about giving DisplayMemberPath in the xaml.
Khaniya 13-Jan-11 5:20am    
@Tarun why ItemSource is wrong place, whats wrong with that position?

Make it a dependency property and you can use it with binding syntax. Hope it helps

Share this answer
Khaniya 13-Jan-11 5:50am    
yes you are right but is there any other way
still want wait for another answer
Take a look at:
StaticResource Markup Extension

Take a look at Using StaticResources in WPF[^]

Here is an example showing how to do what I think you want to accomplish:[^]

Here is an even simpler answer:
Binding WPF ComboBox to a Custom List[^]

CollectionView supports the notions of a "CurrentItem" and and a "CurrentPosition"

And then there is this technical article from Microsoft:
Windows Presentation Foundation Data Binding: Part 2[^]

Espen Harlinn
Share this answer
Khaniya 13-Jan-11 5:23am    
@Espen, Please re-read my subject and question no answer match
I am asking about binding property with my Combobox
If you are not very clear, ask here for clearance
Espen Harlinn 13-Jan-11 5:31am    
ComboBox and ListBox both descends from Selector and shares the same semantics with regards to databinding. The last link is a short answer to a very similar problem, and shows how it might be done.
Khaniya 13-Jan-11 5:37am    
My dear friend but in last link, I can see object of Group class is instantiated but in my case I need to bind with current class property
Hi Khaniya,
Actually where is the actual class objects kept.
Suppose your class object is in the user control like

public YourClass CompanyObject

and your Datagrid is inside the usercontrol , then you can use like,

<DataGridComboBoxColumn Header="Company" ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}},Path=CompanyObject.GetCompany}" Width="200"></DataGridComboBoxColumn>

Good luck
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900