how to set item programmaticly

Nov 16, 2009 at 6:48 PM

hi guys,

to be honest i did not understand how the component work inside. Silverlight and the its animations works so different from and win32 app.

for instance, how should i set the current selected item programmaticly?



Nov 16, 2009 at 11:37 PM


I was just signing up to ask this exact same question! I have been using the control for a few weeks now, and again I'm form an ASP.NET background and have relatively little experience with Silverlight.

I data bind my cover flow to a WCF service. This works great and I can browser thourgh my covers.

What I would really like to be able to do though, is once I have data bound to my service, check a property on the page (actually taken from QueryString - but this bit is already coded) and then select the item within the coverflow.

If I add a button to the page and then set the CoverFlow's SelectedIndex property the control will update itself. However, if I try to call this from the WCF callback method this doesn't work.

Any ideas on how this can be done?

My method structure is as follows:

MainPage() -> Call BindData()
BindData() -> Create WCF proxy class and call Async() method
AsyncCallback() -> Gets fired when WCF service returns. I then bind the results to the coverflow control's ItemSource property. Next I try to call CoverFlow.SelectedIndex = 2 (for example) but the coverflow stays selected at 0

If you need any clarification please feel free to let me know!



Dec 4, 2009 at 8:32 AM

Hi - did anyone get this sorted out? I too am trying to set the selected index programmatically after binding the item source and its not working for me, Any advice greatly recieved :D

Dec 5, 2009 at 10:41 AM
Edited Dec 5, 2009 at 10:42 AM

OK, I solved it....

Add a timer to the top of your xaml.code file,

Dim WithEvents Timer As New DispatcherTimer With {.Interval = New TimeSpan(0, 0, 1)}

Set the items source of your CoverFlow as normal (on loaded for example), then start the timer at the end of the sub/function. On the Tick event, stop the timer and then set the Selected index:


Me.CoverFlow.SelectedIndex = 5



It works. Hope it helps someone out.




Dec 5, 2009 at 10:52 AM

hice to hear that you solved.. : )

could you post more code please?


Dec 6, 2009 at 2:43 PM
john79, declare a timer at the top of your xaml.code file as per my last post. Then load up the itemssource of your CoverFlow control as normal and start the timer:

Me.CoverFlow.ItemSource = MyDataSource

Then just set the selectedindex on the Timer's tick event, something like:

Me.CoverFlow.SelectedIndex = 3

That's it.


From: [email removed]
To: [email removed]
Date: Sat, 5 Dec 2009 03:52:25 -0800
Subject: Re: how to set item programmaticly [SilverlightCoverFlow:75290]

From: john79
hice to hear that you solved.. : )
could you post more code please?
Read the full discussion online.
To add a post to this discussion, reply to this email (
To start a new discussion for this project, email
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at

View your other email accounts from your Hotmail inbox. Add them now.
Dec 7, 2009 at 5:18 PM

I came up with a slightly different solution - but it works for what I'm trying to do.

The code looked something like this:

public partial class MainPage : UserControl
    private int selectedRelease = 0;
    private bool boundControlToPassedRelease = false;

    public MainPage()
        // Other constructor logic
        CoverFlowControl.ItemsChanged += new ItemsChangedEvent(CoverFlowControl_ItemsChanged);

    void CoverFlowControl_ItemsChanged(EventArgs e)
        if (!boundControlToPassedRelease)
            CoverFlowControl.SelectedIndex = 3;
            boundControlToPassedRelease = true;

You obviously need to hook up the items changed event as well. I also extended the CoverFlowControl to allow me to find an object based on one of its properties rather than its index. I did this just by looping through all objects until I find the right one and returning the index. Have any of you come up with a better way to do this?
Dec 9, 2009 at 2:07 PM

could you post the code of your ehnacement?

 it will be nice to include it on original source.


Dec 9, 2009 at 2:39 PM

I also founded another solution :

there was already this method in the samples code

private void UpdatePosition(int index)
	for (int i = 0; i < index; i++)
So after the load completed, before doesn't work. I wrote this 
if (IsolatedStorageSettings.ApplicationSettings.Contains("SelectedIndex"))
	var index = IsolatedStorageSettings.ApplicationSettings["SelectedIndex"];
and in SelectedItemClicked:
void flowControl_SelectedItemClicked(CoverFlowEventArgs e)
	IsolatedStorageSettings.ApplicationSettings["SelectedIndex"] = e.Index;
looks good at moment!
Giovanni D'Arienzo