• 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
maya18222

WPF : How is this code working?

8 posts in this topic

Taken from one of the MSDN examples : http://msdn.microsoft.com/en-us/library/aa970558.aspx

I don't understand how the information in the lower three textboxes of the ContentControl stays synced up with the current selection in the list box. The binding for the ContentControl is bound to an ObservableCollection, which doesnt have any "CurrentItem" functionality. So what is the "IsSynchronizedWithCurrentItem" doing to make this all work?
2

Share this post


Link to post
Share on other sites
[CODE]
<StackPanel>
<TextBlock FontFamily="Verdana" FontSize="11"
Margin="5,15,0,10" FontWeight="Bold">My Friends:</TextBlock>
<ListBox Width="200" IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Source={StaticResource MyFriends}}"/>
<TextBlock FontFamily="Verdana" FontSize="11"
Margin="5,15,0,5" FontWeight="Bold">Information:</TextBlock>
<ContentControl Content="{Binding Source={StaticResource MyFriends}}"
ContentTemplate="{StaticResource DetailTemplate}"/>
</StackPanel>
[/CODE]

But the ListBox must have a some sort of CurrentItem functionality. Actually I'm sure of it. In Webforms, WinForms, controls like Dropdowns and Listboxes have a property to determine what item was selected. So I can't fathom that the WPF/Silverlight Listbox would not have that same functionality. Edited by Alpha_ProgDes
0

Share this post


Link to post
Share on other sites
WPF list boxes inherit from a class called "Selector". Selector, I believe, has a has-a relationship with an object of a class called "Items" or something like that. Items has a CurrentItem property; setting IsSynchronizedWithCurrentItem to true tells WPF to keep this CurrentItem property in sync with the listbox selection.
0

Share this post


Link to post
Share on other sites
Yes but both the ContentControl and the listbox are being bound to an ObservableCollection. All the ContentControl sees is the ObservableCollection. How is it somehow seeing the current item in the listbox/Selector/Items.
0

Share this post


Link to post
Share on other sites
Oh, I see what you are asking... I don't know the answer and don't have time right now to research it. But what events does ObservableCollection expose? Could it be firing an event on selection that both the ContentControl and the ListBox implementations are listening to?
0

Share this post


Link to post
Share on other sites
It works because an [url="http://msdn.microsoft.com/en-us/library/system.componentmodel.icollectionview.aspx"]ICollectionView[/url] has the CurrentItem property and all collections have a default view instance that [url="http://msdn.microsoft.com/en-us/library/ms752284.aspx"]can be accessed[/url] by calling [url="http://msdn.microsoft.com/en-us/library/system.windows.data.collectionviewsource.getdefaultview.aspx"]GetDefaultView()[/url]. So, when you bind a regular collection, such as an ObservableCollection, then WPF automatically binds to its default view (see [url="http://msdn.microsoft.com/en-us/library/ms752347.aspx#how_to_create_a_view"]Using a default View[/url]). Edited by dmatter
0

Share this post


Link to post
Share on other sites
[quote name='dmatter' timestamp='1348263614' post='4982513']
It works because an [url="http://msdn.microsoft.com/en-us/library/system.componentmodel.icollectionview.aspx"]ICollectionView[/url] has the CurrentItem property and all collections have a default view instance that [url="http://msdn.microsoft.com/en-us/library/ms752284.aspx"]can be accessed[/url] by calling [url="http://msdn.microsoft.com/en-us/library/system.windows.data.collectionviewsource.getdefaultview.aspx"]GetDefaultView()[/url]. So, when you bind a regular collection, such as an ObservableCollection, then WPF automatically binds to its default view (see [url="http://msdn.microsoft.com/en-us/library/ms752347.aspx#how_to_create_a_view"]Using a default View[/url]).
[/quote]

Still not following ... there's two controls, a listbox and a content control which are bound to an observable collection as their Content and ItemSource properties respectively.

Are you saying that the ObservableCollection has an instance of some object that instantiates the ICollectionView interface and uses this object, by default, to track the current item in the ObservableCollection? -- so in essence the ObservableCollection has a current item: it's just stored in some other object? Because ObservableCollection itself isn't an ICollectionView ... it isn't any kind of view; it's a viewmodel right? Edited by jwezorek
0

Share this post


Link to post
Share on other sites
[quote name='jwezorek' timestamp='1348266689' post='4982523']
so in essence the ObservableCollection has a current item: it's just stored in some other object?[/quote]
Yes pretty much. Associated 1-to-1 with your ObservableCollection is a default view. In this example your collection gets bound twice (once to a listbox and once to a content control) and so both times the same implicit view object is used.
1

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