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

XML
public ObservableCollection<Company> GetCompany
    {
        get
        {
            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.
Posted
Updated 12-Jan-11 23:17pm
v2
Comments
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

-Raghu
 
Share this answer
 
Comments
Khaniya 13-Jan-11 5:50am    
yes you are right but is there any other way
still want wait for another answer
thanks
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:
http://stackoverflow.com/questions/896587/wpf-bind-collection-with-collection-to-a-listbox-with-groups[^]

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[^]

Regards
Espen Harlinn
 
Share this answer
 
v3
Comments
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
thanks
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
{
get;
set;
} 


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
 
v2

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