开发者

DataTemplate DataType, no class, just xaml

开发者 https://www.devze.com 2023-04-05 17:55 出处:网络
So I\'m trying to understand some code we have on a project that is in C#/WPF.I\'m pretty new and just learning whatever I can.Looking at one of the .xaml, we have a DataT开发者_如何学Cemplate that la

So I'm trying to understand some code we have on a project that is in C#/WPF. I'm pretty new and just learning whatever I can. Looking at one of the .xaml, we have a DataT开发者_如何学Cemplate that lays out where things go for our app. I want to add some events to it, but there is no code behind the .xaml since it is not a class like other .xamls in our project. The DataType of the DataTemplate points to a ViewModel class, but this class does not see my objects in the DataTemplate. Any thoughts? Thanks.


To add rich event-based behavior to elements created through XAML, you need to utilize attached behaviors.


In addition to the attached behaviors John mentioned above, if you are using MVVM, you can utilize the commanding architecture in WPF. Check out ICommand and implementing those on your ViewModel. You will have something like this:

Command="{Binding YourCommandName}"

0

精彩评论

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