• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
jwezorek

The problem with WPF ...

4 posts in this topic

... is that you can't bind a XAML property to an arbitrary expression.

 

I understand the idea of separating presentation from business logic but presentation and business logic eventually do have to meet in some way. WPF as I understand it only allows this binding to happen using C# properties of a class instance that is a data context ... but C# properties are extremely blunt tools -- basically, if we forget OOP for a minute, C# properties are variables i.e. named values. Every programming language in recent times has offered various ways to access values beyond simple names precisely because simple names are often not rich enough for common use cases e.g. arrays let you access values with a name and an index, etc.

0

Share this post


Link to post
Share on other sites

Vanilla (non-implicit) C# properties have nothing to do with variables, they're simply syntactic sugar to replace the ugly get/set methods of older languages. We naturally associate them with variables because get and set methods usually are, but you can always have a read-only property whose getter returns "x * y".

 

If you want to bind your WPF to an expression, simply create a read-only property whose getter returns your expression. If you implement INotifyPropertyChange and fire it whenever something causes the result of your expression to change, your object should be properly refreshed in the UI. This is the basis of Microsoft's MVVM design pattern, the pattern we're supposed to follow when using WPF.

 

Also, WPF bindings are actually powerful enough to allow searching through arrays and other collections. (Including dictionaries.) You can also bind to XML files.

1

Share this post


Link to post
Share on other sites

If you want to bind your WPF to an expression, simply create a read-only property whose getter returns your expression.

 

yes, but a lot of times the expression isn't something you want to name with specific parameters; maybe a name would make sense with unspecified parameters i.e. maybe it would make more sense for it to be a method.

 

 

vanilla (non-implicit) C# properties have nothing to do with variables

 

 

I meant implicit ones are member variables with the language automatically providing a getter and a setter. They are named values associated with an object. But yeah.

 

How does binding to XML files work?

Edited by jwezorek
0

Share this post


Link to post
Share on other sites

If you want to bind your WPF to an expression, simply create a read-only property whose getter returns your expression.
 
yes, but a lot of times the expression isn't something you want to name with specific parameters; maybe a name would make sense with unspecified parameters i.e. maybe it would make more sense for it to be a method.

In that case you have to resort to using a custom converter with a Convert method that does the call for you. This is the part where WPF can get annoying, especially if it's just for little things like "value - 10." If you have a lot of things like that to bind, you can easily find yourself with over 20 converter classes just for simple expressions. Fortunately, custom converters are pretty straightforwards and you can give your converter properties that hold the method's argument. Since object parameters can be set in XAML, it allows you to set the called method arguments in XAML. As long as you don't want to use a binding to set the arguments, it's not that bad.

 

How does binding to XML files work?

I haven't used it myself so I don't know how well (or bad) it works, but look up XmlDataProvider on MSDN. Basically, it's a data provider just like a normal database data providers, except that instead of binding to a database, it binds to XML. It looks like you can use XPath to search through the file.

1

Share this post


Link to post
Share on other sites

In that case you have to resort to using a custom converter with a Convert method that does the call for you. This is the part where WPF can get annoying, especially if it's just for little things like "value - 10." If you have a lot of things like that to bind, you can easily find yourself with over 20 converter classes just for simple expressions. Fortunately, custom converters are pretty straightforwards and you can give your converter properties that hold the method's argument. Since object parameters can be set in XAML, it allows you to set the called method arguments in XAML. As long as you don't want to use a binding to set the arguments, it's not that bad.

 

I've used custom converters before but never thought about it like this. You know, you're right ... custom converters essentially allow you to bind to functions. I wonder if there would be some way to genericize this idea a little ... Need to think about it.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0