c# - TypeConverterMarkupExtension error on setting ImageSource of UserControl -


i'm trying embed image user control. see many posts topic, , tried lot of combination, cannot work.

<usercontrol x:class="audioboxcontroller.audioboxitem"              x:name="audioboxitemcontrol"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"               mc:ignorable="d" width="200" height="250">   <grid>      <image name="image" margin="10" verticalalignment="center"             source="{binding path=imagesource, mode=oneway}"/>    </grid> </usercontrol> 

in code behind have create dp image:

public partial class audioboxitem : usercontrol {   public audioboxitem()   {     initializecomponent();     datacontext = this;   }    public static dependencyproperty sourceproperty =        dependencyproperty.register("imagesource", typeof(imagesource), typeof(audioboxitem));    public imagesource imagesource   {     { return (imagesource)getvalue(sourceproperty); }     set { setvalue(sourceproperty, value); }   } } 

now, in window use it:

<local:audioboxitem x:name="ctrlmike"                      grid.column="0"                       verticalalignment="center"                      imagesource="/audioboxcontroller;component/images/speakers.png"/> 

at design time correctly see image, instead, when run error:

a first chance exception of type 'system.windows.markup.xamlparseexception' occurred in presentationframework.dll  additional information: 'an exception thrown when specification of value of 'system.windows.baml2006.typeconvertermarkupextension'.' line number '19' e line position '60'. 

where i'm wrong?

edit

i changed source image "embedded resource" "content" , use relative path:

<local:audioboxitem x:name="ctrlmike"                      grid.column="0"                       verticalalignment="center"                      imagesource="images/speakers.png"/> 

in way works...so, syntax have use if image "embedded resource"?

your problem dependencyproperty declaration.

firstly, sourceproperty should imagesourceproperty

secondly, believe need add propertymetadata argument dependencyproperty declaration in order support oneway bindings

public static dependencyproperty sourceproperty =        dependencyproperty.register("imagesource", typeof(imagesource), typeof(audioboxitem), new propertymetadata(null)); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -