开发者

WPF Expression blend calling a method on data source programmatically

I am a bit puzzle by this problem.

I have created a library assembly with visual studio 2010 that exposes several things, like observable collections and methods to report some data.

Then I created a WPF project in Expression Blend 4 that has a reference to this assembly and I also created a datasource object from this assembly. So far so good.

When I look in the data view of Blend 4, I can see the observable collections and methods of the data source. I can successfully bind the observable co开发者_如何转开发llection to a datagrid or bind the method in XAML to a button.

But, in a very specific case, I need to programmatically call one of the methods of the datasource in my cs file. What should I do?


In the code behind you can grab a handle to the data source:

var _dataSource = Resources["YourObjectTypeDataSource"] as YourObjectType;

Now in your code behind you can call methods (or set properties, etc.) on the data source instance directly:

_dataSource.YourMethodName();

That being said I'm sure there is a no code behind option available, but I would need to know more about the requirements to suggest a different approach.


Have a look at this question/answer it refers to the only way I know without using any C# code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜