Reputation: 6347
i have a problem, i have some data in Datacontext and i want to fetch this data how can i achive it
thanks in advance shashank
button1.DataContext = new DataView(tablename, "field1 in (" + stringbuilder.ToString() + "0)", "field1", DataViewRowState.CurrentRows);
Upvotes: 0
Views: 1740
Reputation: 2590
how you want to access it? from xaml or in code? or do you use an mvvm-like aproach?
ok from code, its as someone noted before:
if(button1.DataContext is DataView)
{
DataView view = (DataView)button1.DataContext;
//do what you want with your DataView here
}
Upvotes: 0
Reputation: 38025
The DataContext
is a special field that works by setting the default binding target of an element and all of its sub-elements. So for example, you can bind to sub-properties of your DataContext by just specifying a path like so:
<StackPanel DataContext="{DynamicResource selectedBook}">
<TextBlock Text="{Binding Path=Title}" />
<TextBlock Text="{Binding Path=Author}" />
</StackPanel>
Of course, to get the DataContext from code, just access the DataContext
property and cast it to whatever type you need:
MyClass context = (MyClass)this.DataContext;
....
Upvotes: 1
Reputation: 16788
Who don't you fetch the data first before assigning it to the DataContext.
Upvotes: 0