c# - Databinding in WPF -
i having trouble databinding in text block.
what want whenever there exception occured in class want dispaly in text block reason not dispalying.
main.xaml
<window x:class="testingwpf.main" <window.resources> <objectdataprovider x:key="showerr" objecttype="{x:type local:errorlog}" methodname="geterror"/> </window.resources> <frame name="frame1" width="620"/> <button name="button1" click="button1_click"> <textblock name="txtblock6" text="{binding source={staticresource showerr}}"/> </window>
main.xaml.cs
namespace testingwpf { public partial class main : window { private void button1_click(object sender, routedeventargs e) { frame1.source =new uri("/page1.xaml", urikind.relative); } } public class errorlog { private string errorinfo { get; set; } public string geterror(string errormessage) { return errorinfo =errormessage; } } }
page1.xaml
<page x:class="testingwpf.page1" <button name="button1" click="button1_click"> <button name="button2" click="button2_click"> </page>
page1.xaml.cs
namespace testingwpf { public partial class page1 : page { errorlog errorlog = new errorlog (); private void button1_click(object sender, routedeventargs e) { somemethod1(); } private void somemethod1() { try { } catch(expection e) { errorlog.geterror(e.tostring());// not dispalying } } private void button2_click(object sender, routedeventargs e) { somemethod2(); } private void somemethod2() { class2 class2 = new class2(); class2.foo(); } } }
class2.cs
namespace testingwpf { class class2 { errorlog errorlog = new errorlog (); public void foo() { try { } catch(expection e) { errorlog.geterror(e.tostring());// not dispalying } } } }
where set error see geterror method returns same message pass it? either add parameterless geterror
method or bind actual property of object creating, i.e. create publicly accessible property
error {get;set;}
in errorlog class , set in seterror method, i.e.
public string seterror(string errormessage) { error = errormessage; }
Comments
Post a Comment