wpf - Keep getting error: The tag does not exist in XML namespace -
i have project test multibinding. want binding data textbox2 , textbox3 textbox1. tried again , again still got error.
xaml:
<window x:class="test_multibiding.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="621" xmlns:c="clr-namespace:test_multibiding"> <window.resources> <c:stringformatconverter x:key="strconverter"/> </window.resources> <grid> <textbox textwrapping="wrap" acceptsreturn="true" height="269" horizontalalignment="left" margin="376,22,0,0" name="textbox1" verticalalignment="top" width="211" > <textbox.text> <multibinding converter="{staticresource strconverter}" stringformat="test {0} test {1} blabla"> <binding elementname="textbox2" path="text"/> <binding elementname="textbox3" path="text"/> </multibinding> </textbox.text> </textbox> <textbox height="40" horizontalalignment="left" name="textbox2" verticalalignment="top" width="222"/> <textbox height="40" horizontalalignment="left" name="textbox3" verticalalignment="top" width="222"/> </grid> mainwindow
namespace test_multibiding { /// <summary> /// interaction logic mainwindow.xaml /// </summary> public partial class mainwindow : window { public mainwindow() { initializecomponent(); } public class stringformatconverter : imultivalueconverter { public object convert(object[] values, type targettype, object parameter, system.globalization.cultureinfo culture) { return string.format(parameter.tostring(), values); } public object[] convertback(object value, type[] targettypes, object parameter, system.globalization.cultureinfo culture) { throw new notsupportedexception("cannot convert back"); } } } } and got error:
the tag 'stringformatconverter' not exist in xml namespace 'clr-namespace:test_multibiding'. so please tell me where's problem?
there few of things wrong here. first, don't need converter. stringformat property of multibinding you. second, if want use custom converter, need set converterparameter on multibinding, not stringformat.
now, reason why converter isn't in namespace: declared inside window class. full name of converter test_multibiding.mainwindow.stringformatconverter. compile (but converter have nullreferenceexception parameter null) if change class to:
namespace test_multibiding { /// <summary> /// interaction logic mainwindow.xaml /// </summary> public partial class mainwindow : window { public mainwindow() { initializecomponent(); } } public class stringformatconverter : imultivalueconverter { public object convert(object[] values, type targettype, object parameter, system.globalization.cultureinfo culture) { return string.format(parameter.tostring(), values); } public object[] convertback(object value, type[] targettypes, object parameter, system.globalization.cultureinfo culture) { throw new notsupportedexception("cannot convert back"); } } }
Comments
Post a Comment