c# - Updating label content within a method -
i need change wpf label content within process, tried no content change in real time. doing wrong?
event caller:
private void connect_button_mousedown(object sender, mousebuttoneventargs e) { mouse.overridecursor = cursors.wait; labelststusupdate("connecting.."); // status changer config = new configuration(); bool status = config.connectviausb(); mouse.overridecursor = null; if (!status) { labelststusupdate("disconnected");// status changer } else { labelststusupdate("connected");// status changer } } status changer method:
private void labelststusupdate(string message) { dispatcher.begininvoke(dispatcherpriority.background, (sendorpostcallback)delegate { available_amount_label.content = message; }, null); }
this code recent application changing value of label in runtime try find workaround this
public partial class mainwindow : window { int value=0; private delegate void updatemylabel(system.windows.dependencyproperty dp, object value); private void processmerge() { updatemylabel updatelabeldelegate = new updatemylabel(_mylabel.setvalue); foreach (var item in collections) { string _mylabel= "process completed..." + value.tostring() + " %"; dispatcher.invoke(updatelabeldelegate, system.windows.threading.dispatcherpriority.background, new object[] { system.windows.controls.label.contentproperty, _mylabel}); value++; } } } }
Comments
Post a Comment