It may be because you are not giving the resources names? I thought that with Silverlight 1.1 and above, all elements in a ResourceDictionary [including Storyboard] must have their x:Name set... I may be wrong though, I'll have to double check with the
actual code tomorrow.
Nop, "THIS" is refering to my USERCONTROL i am trying to add to my resources an animation i am creating in that case is the storyboard.... the thing is the Foreach ... i believe it is giving the same name to all my storyboard an can not give the same name
... but that's why i created the INDEX so i can create my names... or keys.... but even like that the error appears-.
Ivana A. Tilca | Microsoft Student Partner | Channel 8 editor | Microsoft
var u = from element in LayoutRoot.Children
where element is UIElement
select element;
foreach (var itm in u)
{
myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.Duration = duration;
myDoubleAnimation.From = 0;
sbImageAppear = new Storyboard();
sbImageAppear.Duration = duration;
sbImageAppear.Children.Add(myDoubleAnimation);
TimeSpan time = new TimeSpan(0, 0, 0, 0, timeCounter);
sbImageAppear.BeginTime = time;
ivanatilca
Member
113 Points
110 Posts
Re: Object creation by using xaml fails
Jun 25, 2008 04:41 AM | LINK
Nop, "THIS" is refering to my USERCONTROL i am trying to add to my resources an animation i am creating in that case is the storyboard.... the thing is the Foreach ... i believe it is giving the same name to all my storyboard an can not give the same name ... but that's why i created the INDEX so i can create my names... or keys.... but even like that the error appears-.
http://ivanatilca.com.ar
ivanatilca
Member
113 Points
110 Posts
Re: Re: Object creation by using xaml fails
Jun 25, 2008 04:43 AM | LINK
The error is in the line... this.Resources.Add(index.ToString(), sbImageAppear); says i already have that key...
http://ivanatilca.com.ar
SteveWong
Contributor
6769 Points
1351 Posts
Re: Re: Re: Object creation by using xaml fails
Jun 25, 2008 04:58 AM | LINK
If you do the second time, it is sure that a storyboard with the same key had been added
So you have to remove it before adding it
this.Resources.Remove(index.ToString());
As I remember , It shouldnt throw any error even the key is not there
SteveWong (HongKong)
Please mark post as answer if they help you
ivanatilca
Member
113 Points
110 Posts
Re: Re: Re: Object creation by using xaml fails
Jun 25, 2008 12:10 PM | LINK
Yes! That's it! Thanks!!!! The final code....
if (this.Resources.Contains(index.ToString()))
{
this.Resources.Remove(index.ToString());
}
this.Resources.Add(index.ToString(), sbImageAppear);
http://ivanatilca.com.ar