If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How to get my custom object in WPF ListBox?

Hey,
I am trying to get an object from my WPF ListBox. I have a WPF usercontrol(ResultsControl) and it uses a Listbox(lbResults) to Display my custom Objects from a Win form. I am making a new WPF usercontrol(ShowInfoUserControl) to display my custom object's information. The showInfoUserControl should only become visible with the objects's information, when I press on an object in the WPF ListBox. I use Hyperlink to tick the showInfoUserControl. I have tried to lbResults.SelectedItem and lbResults.SelectedValue without luck. Could any one help me please? Every advice will be grateful.

Re: How to get my custom object in WPF ListBox?

Method
Fireup Blend, create a new WPF Application Project, drop in a ListBox.
I'm going to grab my ListBoxItems from an external XML file. This could just as easily be a collection in VB.NET/C# (does anybody want/need a post on databinding to CLR Objects?)
ie: items.xml

Select the ListBox, Properties, ItemSource, Data Binding, "+ XML", and select items.xml.
If that works, you should see a bunch of items in the listbox.
The Animation
Now we'll have to delve into the XAML code (hit F11), and create a DataTemplate.

The main thing to focus on is the DataTrigger.EnterActions and ExitActions. This is the actual animation, where EnterActions are when the Trigger is True, and ExitActions are when the Trigger is False.
In this case, the trigger is the 'IsSelected' property of the "Ancestor" (aka, Parent, which is the ListBoxItem).
The animation itself will increase the fontsize from 16 to 22 when selected, and then 22 to 16 when deselected.