Problems removing an element
Last post 10-10-2007 4:44 PM by y_makram. 10 replies.
Sort Posts:
10-09-2007 5:53 PM
Problems removing an element

I'm having a problem where an element I'm trying to remove is still visible 

I have a very simple XAML file

<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Loaded="set_resize_listener">
       <Canvas x:Name = "loader_canvas">
    <Image x:Name="loader" Source="/community/images/loader.png" Width="710" Height="480" />
    </Canvas>
   <MediaElement x:Name="media" Width="710" Height="480" Source="feed.asx" />
</Canvas>

 

And here, I'm trying to remove the loader element as you can still see it showing behind the player once it starts playing

function buffer_start_check(sender, args)
{   
    var player = sender.findName("media");
    if(player.BufferingProgress == 100)
    {
        player.removeEventListener("BufferingProgressChanged", buffer_token);
        //Play the video
        player.Play();
       
        var loader_canvas = sender.findName("loader_canvas");
        var loader_image = sender.findName("loader");
        loader_canvas.children.remove(loader_image);
    }
}

 

Even adding the following doesn't remove or hide the element

var loader_canvas = sender.findName("loader_canvas");
        loader_canvas.width = 0;
        loader_canvas.height = 0;
        loader_canvas.visibility = "Collapsed";
        var loader_image = sender.findName("loader");
        loader_image.width = 0;
        loader_image.height = 0;
        loader_canvas.children.remove(loader_image);

Jhorra

Loading...
Joined on 08-29-2004
Phoenix, Az
Posts 373
10-09-2007 6:13 PM
Re: Problems removing an element

 Can you please try to replace sender.findName with sender.getHost().content.findName

I used the remove method before and it effectively hides the removed element. So I suspect that the issue is with finding the element to remove. So using findName on the root control will ensure that the full hierarchy is searched 

Thanks
Yasser Makram
My Blog: http://www.silverlightrecipes.com
Sr. Architect
Santeon Inc. Microsoft Silverlight Partner, Solution Provider

y_makram

Loading...
Joined on 06-07-2007
Cairo, Egypt
Posts 1,141
10-09-2007 6:21 PM
Re: Re: Problems removing an element

I've changed the function to now look like this, it still doesn't hide the element

 function buffer_start_check(sender, args)
{   
    var player = sender.findName("media");
    if(player.BufferingProgress == 100)
    {
        player.removeEventListener("BufferingProgressChanged", buffer_token);
        //Play the video
        player.Play();
       
        var loader_canvas = sender.getHost().content.findName("loader_canvas");
        loader_canvas.width = 0;
        loader_canvas.height = 0;
        loader_canvas.visibility = "Collapsed";
        var loader_image = sender.getHost().content.findName("loader");
        loader_image.width = 0;
        loader_image.height = 0;
        loader_canvas.children.remove(loader_image);
    }
}
 

Jhorra

Loading...
Joined on 08-29-2004
Phoenix, Az
Posts 373
10-09-2007 6:28 PM
Re: Re: Problems removing an element

The bufferingprogress value ranges between 0 and 1, so your remove logic is probably never called. To make sure of that place an alert inside the if block. Your code should be if(player.BufferingProgress == 1)

Thanks
Yasser Makram
My Blog: http://www.silverlightrecipes.com
Sr. Architect
Santeon Inc. Microsoft Silverlight Partner, Solution Provider

y_makram

Loading...
Joined on 06-07-2007
Cairo, Egypt
Posts 1,141
10-09-2007 6:40 PM
Re: Re: Re: Problems removing an element

So does 1 mean it's completely loaded?  How do I tell when it's 100%? 

Jhorra

Loading...
Joined on 08-29-2004
Phoenix, Az
Posts 373
10-09-2007 6:46 PM
Re: Re: Re: Re: Problems removing an element

Also, I'm pretty sure it's being fired, otherwise my video wouldn't start playing, which it does. 

Jhorra

Loading...
Joined on 08-29-2004
Phoenix, Az
Posts 373
10-09-2007 6:55 PM
Marked as Answer
Re: Re: Re: Re: Problems removing an element

Yes 1 means that the buffering is done. The event is firing, but I am talking about satisfying the condition. the buffering progress will never be 100 so the condition will never be true. So please change the condition to == 1 instead of == 100

Thanks
Yasser Makram
My Blog: http://www.silverlightrecipes.com
Sr. Architect
Santeon Inc. Microsoft Silverlight Partner, Solution Provider

y_makram

Loading...
Joined on 06-07-2007
Cairo, Egypt
Posts 1,141
10-09-2007 6:59 PM
Re: Re: Re: Re: Re: Problems removing an element

Thanks looks like that was it. 

Jhorra

Loading...
Joined on 08-29-2004
Phoenix, Az
Posts 373
10-09-2007 7:01 PM
Re: Re: Re: Re: Re: Problems removing an element
Thank you, glad it worked

Thanks
Yasser Makram
My Blog: http://www.silverlightrecipes.com
Sr. Architect
Santeon Inc. Microsoft Silverlight Partner, Solution Provider

y_makram

Loading...
Joined on 06-07-2007
Cairo, Egypt
Posts 1,141
10-10-2007 12:01 PM
Re: Problems removing an element

y_makram:

So using findName on the root control will ensure that the full hierarchy is searched 

I'm pretty sure findName searches the entire namescope regardless of which element in the namescope it is called on.  Have you had a situation where this wasn't the case?

swirlingmass

Loading...
Joined on 05-02-2007
Posts 384
10-10-2007 4:44 PM
Re: Problems removing an element

 You are right :), sometimes I skip reading the documentation, but it always pays off to do. Thank you :)

Thanks
Yasser Makram
My Blog: http://www.silverlightrecipes.com
Sr. Architect
Santeon Inc. Microsoft Silverlight Partner, Solution Provider

y_makram

Loading...
Joined on 06-07-2007
Cairo, Egypt
Posts 1,141
Page view counter