This is a migrated thread and some comments may be shown as answers.

Carousel selected item

5 Answers 256 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
N
Top achievements
Rank 1
N asked on 24 Jun 2009, 12:18 PM
Hi,

I have a requirement to refresh the carousel control every minute with data. I am using a custom entity to populate the carousel with data and have defined a data template for the same.
I have managed to refresh the carousel - however, after refresh the same item should be at the centre of the carousel as before the refresh. I am using the below code to do the bring the item into view, but it doesnt seem to work.

Telerik.Windows.Data.

Record objRec = rdcTasks.SelectedRecord;

 

RadCarouselPanel panel = this.rdcTasks.FindCarouselPanel(); 
this.rdcTasks.ItemsSource = this.CreateItemSource();
panel.BringDataItemIntoView(objRec);

In debug mode when I check the value of objRec, it shows the correct data record. However, it does not bring it to the centre. 

Also, I need to set a different colour for the data record at the centre of the carousel. How can I achieve this?

Thanks in advance.

 

 

 

5 Answers, 1 is accepted

Sort by
0
Timothy Lee Russell
Top achievements
Rank 2
answered on 24 Jun 2009, 04:52 PM

public delegate void SimpleDelegate(); 
 
this.Dispatcher.BeginInvoke(DispatcherPriority.Input, new SimpleDelegate(delegate { BringIntoView() })); 

Inactive The enumeration value is 0. Operations are not processed.
SystemIdle The enumeration value is 1. Operations are processed when the system is idle.
ApplicationIdle The enumeration value is 2. Operations are processed when the application is idle.
ContextIdle The enumeration value is 3. Operations are processed after background operations have completed.
Background The enumeration value is 4. Operations are processed after all other non-idle operations are completed.
Input The enumeration value is 5. Operations are processed at the same priority as input.
Loaded The enumeration value is 6. Operations are processed when layout and render has finished but just before items at input priority are serviced. Specifically this is used when raising the Loaded event.
Render The enumeration value is 7. Operations processed at the same priority as rendering.
DataBind The enumeration value is 8. Operations are processed at the same priority as data binding.
Normal The enumeration value is 9. Operations are processed at normal priority. This is the typical application priority.
Send The enumeration value is 10. Operations are processed before other asynchronous operations. This is the highest priority.


I'm not sure that this will work for you but it worked for me in another area that sounds similar.  Basically, you can use a delegate to set the DispatcherPriority making your BringIntoView method more important.  You probably can't use a SimpleDelegate because you are passing it a parameter.  This link shows how to pass a parameter.

To get my TextBox.Focus() event to work in every situation, I had to set the DispatcherPriority to the "Input" level.


0
Timothy Lee Russell
Top achievements
Rank 2
answered on 24 Jun 2009, 07:14 PM
I tried out using the dispatcher to set the event priority higher -- it doesn't seem to work...

It seems that if the item you are trying to bring into view is out of the "viewport" it doesn't work -- if it is "visible" (although not the foremost item), it does work...

Telerik...?
0
Milan
Telerik team
answered on 26 Jun 2009, 01:10 PM
Hi N Muppalla,

When you rebind the carousel all records are recreated - new instances are created. When you try to bring into view the previsously selected record (which is no longer a part of the new record collection) the record cannot be found in the new record collection and thus it cannot be navigated to.

A better aproach is to determine the selectedIndex before you rebind and after that use that index to navigate after the carousel is rebound.

Here is a snippet tha should work for your scenario:

private void Button_Click(object sender, RoutedEventArgs e)  
{  
    int selectedIndex = this.RadCarousel1.Records.IndexOf(this.RadCarousel1.SelectedRecord);  
    this.RadCarousel1.ItemsSource = this.CreateData();  
    var panel = this.RadCarousel1.FindCarouselPanel();  
 
    this.Dispatcher.BeginInvoke(  
        (Action)delegate 
    {  
        panel.BringDataItemIntoView(this.RadCarousel1.Records[selectedIndex]);  
    },  System.Windows.Threading.DispatcherPriority.SystemIdle, null);  


Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
N
Top achievements
Rank 1
answered on 30 Jun 2009, 08:26 AM
Thanks Milan. It works perfectly now when the grid refreshes.
As I mentioned in my original post, I also need to be able to set a different colour for the item that has been selected in the carousel. Could you please advise on how I can achieve this?
Thanks in advance.
0
Milan
Telerik team
answered on 03 Jul 2009, 09:21 AM
Hi N,

To do that you will have to create new template for CarouselItem and use triggers to change the background color when the IsSelected property changes. I have prepared a sample application that demonstrates how this can be done.

What kind of criteria would you like to check for? Will you check for certain proverty values of your data objects?

For our next release we will try to redo our default styles and templates so that simple modification like that could be make without redefining the whole template.

Sincerely yours,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Carousel
Asked by
N
Top achievements
Rank 1
Answers by
Timothy Lee Russell
Top achievements
Rank 2
Milan
Telerik team
N
Top achievements
Rank 1
Share this question
or