Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

Why won't my external image load in my Silverlight Page? -


to make simple possible, created new default silverlight 4 application , added images folder test web site automatically created when application generated. put same image, let's call "imagename.png" in clientbin folder , images folder. now, works fine when use image in clientbin using xaml this:

<grid x:name="layoutroot" background="white">     <stackpanel>         <image source="imagename.png" width="16" height="16"/>         <textbox text="hello" />     </stackpanel> </grid> 

but image doesn't load when try access image in images folder this:

<grid x:name="layoutroot" background="white">     <stackpanel>         <image source="../images/imagename.png" width="16" height="16"/>         <textbox text="hello" />     </stackpanel> </grid> 

i don't errors, image isn't there. can tell me what's going on? i've been able find seems suggest should work.

the problem here folder containing xap , top content in xap considered @ root of path. hence path "/" maps top content in xap , folder xap sited (usually clientbin). attempt use parent path past considered root result in silverlight network error.

any content outside of folder xap found in can accessed using absolute uri.

what need convert relative address containing parent path absolute address before passing image.source property. preferably want avoid hardcoding base absolute address source code.

we can current acquire absolute url xap using baseaddress property of webclient object. can compose desired absolute address combining relative address 1 contains parent path.

a value converter can make easier in xaml:-

public class webrelativeconverter : ivalueconverter {     public uri base { get; set; }      public webrelativeconverter()     {         base = new uri((new webclient()).baseaddress, urikind.absolute);     }      public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         uri result = null;          if (value uri)         {             result = new uri(base, (uri)value);         }         else if (value != null)         {             result = new uri(base, value.tostring());         }         return result;     }      public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         throw new notimplementedexception();     } } 

now fixed value in xaml this:-

<grid x:name="layoutroot" background="white">     <grid.resources>          <local:webrelativeconverter x:key="wrc" />     </grid.resources>     <stackpanel>         <image datacontext="../images/imagename.png" source="{binding converter={staticresource wrc}}" width="16" height="16"/>         <textbox text="hello" />     </stackpanel> </grid> 

now if binding source uri or string property of object need add converter , should work.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -