silverlight - In a xaml file, how can I use a event handler from another cs file? -
for example, have button click event in xaml file: < button x:name="buttonfindcoordinate" content="map coordinate" click="buttonfindcoordinate_click" />
to knowledge, buttonfindcoordinate_click event handler must function code behind cs file. there way can reference event handler cs file in xaml file (for example, button aa.xaml file, , have event handler function saved in bb.cs)? how can write code?
thanks,
wei
i better practice extract logic of handler separate class have both click handlers call same method.
for example
in a.xaml.cs
private void buttonfindcoordinate_click(object sender, eventargs e) { string postcode = coordinatefinder.findpostcode(txtbuttonfind.text); }
and b.xaml.cs
private void otherbutton_click(object sender, eventargs e) { string postcode = coordinatefinder.findpostcode(txtsomeotherfield.text); }
and coordinatefinder class like.
public class coordinatefinder { public static string findpostcode(string coordinates) { // shared code here. } }
the reason it's better practice not 'share' click handler across classes, want code readable , maintainable possible.
imagine if come in few months , see click handler class b calling click handler class - have read click handler of discover does.
furthermore if (or on team) update aa.xaml.cs, might access fields aa.xaml break bb.cs without knowledge.
hope helps -
Comments
Post a Comment