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.
my method to get my custom objects (code behind for ResultsControl)
public void GetResults(Result result)
{
WPFResult wpfResult = new WPFhResult(result.ObjectId, result.Header, result.Name);
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
<?xml version="1.0" encoding="utf-8" ?>
<Items xmlns="">
<Item>Foo</Item>
<Item>Bar</Item>
<Item>The Fooiest Of Bars</Item>
<Item>The Bariest of Foos</Item>
</Items>
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.
Bookmarks