Note that there are some explanatory texts on larger screens.

plurals
  1. POControl.Text in WPF
    primarykey
    data
    text
    <p>Currently I am in the process of converting one of my programs from WinForms to WPF. The first problem I have run into involves setting the text value of a control in WPF. In my WinForms program, I have working code that looks like this:</p> <pre><code>delegate void SetTextCallback(Control c, string text); private void SetText(Control c, string text) { if (c.InvokeRequired) { SetTextCallback d = new SetTextCallback(SetText); this.Invoke(d, new object[] {c, text}); } else { c.Text = text; //This is where I have not found a way to replicate. } } </code></pre> <p>I have changed a few things to get part to work, but so far, this is what I have in WPF that seems to work except for the part where I am actually trying to set the text of the control.</p> <pre><code>delegate void SetTextCallback(Control c, string text); private void SetText(Control c, string text) { if (c.Dispatcher.CheckAccess()) { SetTextCallback d = new SetTextCallback(SetText); this.Dispatcher.Invoke(d, new object[] {c, text}); } else { c.Text = text; } } </code></pre> <p>From what I have found out after reading things on this site and the MSDN sections is that I can call the c.Text command if the control was specifically a WPF textbox and then the c.Content command if the control was specifically a WPF label. However, I can't call either of these for a generic control c like I have here. Is there any method or command that I could use to set the Text value of my control c, or is there another way that I can modify the code so that I can still set up my SetText function that allows me to edit the text of any controls (textbox, label, etc.) in the same manner?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload