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

Refreshing binded radTransitionControl created at runtime.

0 Answers 30 Views
TransitionControl
This is a migrated thread and some comments may be shown as answers.
Ariel
Top achievements
Rank 1
Ariel asked on 14 Aug 2012, 02:17 PM
Hi, I have a silverlight application that create many radTileViewItems at runtime. Each item have a FuildControl, and a radTransitionControl into the smallcontent, content, and largeContent. Each TransitionControl have an intemTemplate with an Image.

Something like this, but created at runtime:

<telerik:RadTileViewItem Header="Av. Rivadavia y Av. Pueyrredón" Width="{StaticResource TileViewItemWidth}" Height="{StaticResource TileViewItemHeight}">
                       <telerik:RadFluidContentControl ContentChangeMode="Manual">
                        <telerik:RadFluidContentControl.SmallContent>
                            <telerik:RadTransitionControl x:Name="RadTCCam1s"  Duration="00:00:01" TransitionStatusChanged="RadTC_TransitionStatusChanged">
                                <telerik:RadTransitionControl.ContentTemplate>
                                    <DataTemplate>
                                        <Image Source="{Binding}" Stretch="Fill" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                                    </DataTemplate>
                                </telerik:RadTransitionControl.ContentTemplate>
                                <telerik:RadTransitionControl.Transition>
                                    <telerik:FadeTransition />
                                </telerik:RadTransitionControl.Transition>
                            </telerik:RadTransitionControl>
                        </telerik:RadFluidContentControl.SmallContent>
                        <telerik:RadFluidContentControl.SmallContent>
                           .
                           .
                           .
                        </telerik:RadFluidContentControl.Content>
                        <telerik:RadFluidContentControl.LargeContent>
                           .
                           .
                           .
                        </telerik:RadFluidContentControl.LargeContent>

This works fine the first time I binding the datatemplates, but when I trying to change the images, I still looking the previous Images.

this is the webservice callback that I use to refresh the images

        void wsCW_GetRefreshWebCompleted(object sender, wsCamarasWeb.GetCamarasWebCompletedEventArgs e)
        {
            int rtCount = 0;

            if (!e.Cancelled && e.Error == null && itemsLoaded)
            {
                foreach (RadTileViewItem rtvi in rtlvCamaras.Items)
                {
                    if (!ExcludeThisItem(rtvi))
                    {
                        RadTransitionControl rtcsc = ((RadTransitionControl)((RadFluidContentControl)rtvi.Content).SmallContent);
                        RadTransitionControl rtcc = ((RadTransitionControl)((RadFluidContentControl)rtvi.Content).Content);
                        RadTransitionControl rtclc = ((RadTransitionControl)((RadFluidContentControl)rtvi.Content).LargeContent);

                        LoadNewImage(rtcsc, GetImagesProxyUrl() + e.Result.Where(x => GetTransitionCtrlName(x) + "SC" == rtcsc.Name).First().Codigo + "&rnd=" + "rtcsc" + (++rtCount).ToString() + DateTime.Now.Millisecond.ToString());
                        LoadNewImage(rtcc, GetImagesProxyUrl() + e.Result.Where(x => GetTransitionCtrlName(x) + "C" == rtcc.Name).First().Codigo + "&rnd=" + "rtcc" + (++rtCount).ToString() + DateTime.Now.Millisecond.ToString());
                        LoadNewImage(rtclc, GetImagesProxyUrl() + e.Result.Where(x => GetTransitionCtrlName(x) + "LC" == rtclc.Name).First().Codigo + "&rnd=" + "rtclc" + (++rtCount).ToString() + DateTime.Now.Millisecond.ToString());
                    }
                }                
            }
        }

GetImagesProxyUrl() get the proxy that I use to avoid Cross-Domain restrictions.

        private void LoadNewImage(RadTransitionControl radTC, string uri)
        {
            loadingImages.Add(uri, radTC);

            BitmapImage bitmapImage = new BitmapImage();

            bitmapImage.ImageOpened += new EventHandler<RoutedEventArgs>(bitmapImage_ImageOpened);
            bitmapImage.ImageFailed += new EventHandler<ExceptionRoutedEventArgs>(bitmapImage_ImageFailed);
            bitmapImage.DownloadProgress += new EventHandler<DownloadProgressEventArgs>(bitmapImage_DownloadProgress);

            bitmapImage.UriSource = new Uri(uri, UriKind.Absolute);
            bitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;            
        }

loadingImages is a keyValue collection, the key is the url foreach image, and the value is the radtransitionControl.

        private void bitmapImage_ImageOpened(object sender, RoutedEventArgs e)
        {
            BitmapImage bitmapImage = (BitmapImage)sender;
            string imgKey = bitmapImage.UriSource.AbsoluteUri;

            if (loadingImages.ContainsKey(imgKey))
            {
                loadingImages[imgKey].CacheMode = null;                
                loadingImages[imgKey].Content = new ItemImageBindingSource(bitmapImage);
                loadingImages[imgKey].ContentTemplate.LoadContent();
                loadingImages[imgKey].ApplyTemplate();
                loadingImages.Remove(imgKey);
            }

            bitmapImage.ImageOpened -= new EventHandler<RoutedEventArgs>(bitmapImage_ImageOpened);
            bitmapImage.ImageFailed -= new EventHandler<ExceptionRoutedEventArgs>(bitmapImage_ImageFailed);
            bitmapImage.DownloadProgress -= new EventHandler<DownloadProgressEventArgs>(bitmapImage_DownloadProgress);
        }

I use the LoadNewImage() method the first time, and this work, but doesn't work to refresh the images.

This is the webservice callback that create the controls the first time.

       void wsCW_GetCamarasWebCompleted(object sender, wsCamarasWeb.GetCamarasWebCompletedEventArgs e)
        {
            if (!e.Cancelled && e.Error == null)
            {

                for (int i = (rtlvCamaras.Items.Count - 1); i >= 0 ; i--)
                {
                    if (!ExcludeThisItem((RadTileViewItem)rtlvCamaras.Items[i]))
                    {
                        rtlvCamaras.Items.RemoveAt(i);
                    }
                }
                
                foreach (wsCamarasWeb.EntCamarasWeb cw in e.Result)
                {
                    RadTileViewItem tvItem = new RadTileViewItem();
                    RadFluidContentControl fluid = new RadFluidContentControl();
                    RadTransitionControl transitionSC = new RadTransitionControl();
                    RadTransitionControl transitionC = new RadTransitionControl();
                    RadTransitionControl transitionLC = new RadTransitionControl();
                    transitionSC.Name = GetTransitionCtrlName(cw) + "SC";
                    transitionC.Name = GetTransitionCtrlName(cw) + "C";
                    transitionLC.Name = GetTransitionCtrlName(cw) + "LC";
                    fluid.ContentChangeMode = ContentChangeMode.Manual;
                    
                    transitionSC.TransitionStatusChanged += new System.EventHandler<Telerik.Windows.Controls.TransitionControl.TransitionStatusChangedEventArgs>(RadTC_TransitionStatusChanged);
                    transitionC.TransitionStatusChanged += new System.EventHandler<Telerik.Windows.Controls.TransitionControl.TransitionStatusChangedEventArgs>(RadTC_TransitionStatusChanged);
                    transitionLC.TransitionStatusChanged += new System.EventHandler<Telerik.Windows.Controls.TransitionControl.TransitionStatusChangedEventArgs>(RadTC_TransitionStatusChanged);

                    transitionSC.Duration = new TimeSpan(0, 0, 2);
                    transitionC.Duration = new TimeSpan(0, 0, 2);
                    transitionLC.Duration = new TimeSpan(0, 0, 2);

                    DataTemplate dataTemp = (DataTemplate)XamlReader.Load(@"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007""><Image Source=""{Binding Url}"" Stretch=""Fill"" HorizontalAlignment=""Left"" VerticalAlignment=""Top""/> </DataTemplate>");
                    
                    tvItem.Header = cw.Nombre;

                    tvItem.Width = 194;
                    tvItem.Height = 180;
                    tvItem.Content = fluid;
                    fluid.SmallContent = transitionSC;
                    fluid.Content = transitionC;
                    fluid.LargeContent = transitionLC;                    

                    transitionSC.Transition = new Telerik.Windows.Controls.TransitionEffects.FadeTransition();
                    transitionC.Transition = new Telerik.Windows.Controls.TransitionEffects.FadeTransition();
                    transitionLC.Transition = new Telerik.Windows.Controls.TransitionEffects.FadeTransition();                                        
                
                    transitionSC.ContentTemplate = dataTemp;
                    transitionC.ContentTemplate = dataTemp;
                    transitionLC.ContentTemplate = dataTemp;

                    LoadNewImage(transitionSC, GetImagesProxyUrl() + cw.Codigo + "&rnd=" + "rtcsc" + DateTime.Now.Millisecond.ToString());
                    LoadNewImage(transitionC, GetImagesProxyUrl() + cw.Codigo + "&rnd=" + "rtcc" + DateTime.Now.Millisecond.ToString());
                    LoadNewImage(transitionLC, GetImagesProxyUrl() + cw.Codigo + "&rnd=" + "rtclc" + DateTime.Now.Millisecond.ToString());

                    rtlvCamaras.Items.Add(tvItem);
                }

                ResizeRTV();
                itemsLoaded = true;
            }

Anyone have an idea about why the images doesn't refresh?

No answers yet. Maybe you can help?

Tags
TransitionControl
Asked by
Ariel
Top achievements
Rank 1
Share this question
or