开发者

Good practice or bad practice

开发者 https://www.devze.com 2022-12-31 14:02 出处:网络
i am new to WPF and i have one question(the first one actually, more to come) Is it better to add some logic, for example the bindings for the window, i开发者_开发技巧n xaml or in the code behind.If y

i am new to WPF and i have one question(the first one actually, more to come) Is it better to add some logic, for example the bindings for the window, i开发者_开发技巧n xaml or in the code behind.


If you can put it in XAML, it's generally better to do that than be wiring up stuff in your codebehind.

For one thing, this lets you use tools like Expression Blend more effectively, since you have more stuff available at design time. It also further shifts view logic into the view itself, and helps you stay away from stuffing view-based code in your viewmodels or controllers.


Most people wouldn't consider a binding to be logic. Bindings should generally go in xaml. It is a good idea to put logic in a separate ViewModel class which you bind to.


It's kind of a religious debate right now. With an MVVM approach, you can essentially get away with the only code in your codebehind being the creation of your ViewModel and its assignment to your DataContext.

Even all of your event handling can be managed in your ViewModel using UI Commands.

0

精彩评论

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