开发者

How Can I fetch the Data from DATAContext

i hav开发者_如何学Pythone 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);


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;
....


Who don't you fetch the data first before assigning it to the DataContext.


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  
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜