I am asking for a user to type in what he or she would like to search for, and then I would like to pass this value to another page where the search will be performed and the results will be given. I am using a PhoneTextBox control from the WP Toolkit. On the KeyUp or ActionIconTapped event I would like to get the value entered in the PhonTextBox and pass that to my search page, although I cannot figure out how to get the text value entered?
MainPage.xaml
<toolkit:PhoneTextBox x:Name="publicSearchTextBox" HorizontalAlignment="Stretch" Margin="-10,0,12,0"
Hint="search for topic or name"
ActionIcon="/Resources/Images/search.png"
ActionIconTapped="publicSearchTextBox_ActionIconTapped"
KeyUp="publicSearchTextBox_KeyUp"/>
MainPage.xaml.cs
..get publicSearchTextBox text value and pass this to the search page?
For some reason, I cannot reference the PhoneTextBox in my code behind from setting x:Name="publicSearchTextBox" in my xaml? How is this possible?
Perhaps you have a typo because i made some handlers for the XAML you have above and it works fine for me. Copy paste the following in the code behind and try?
private void PrintTextboxValue()
{
Debug.WriteLine("Value: {0}", publicSearchTextBox.Text);
}
private void publicSearchTextBox_ActionIconTapped(object sender, EventArgs e)
{
PrintTextboxValue();
}
private void publicSearchTextBox_KeyUp(object sender, KeyEventArgs e)
{
PrintTextboxValue();
}
If it does not work then please update your question with more information such as, where you are referencing the PhoneTextBox.
Related
I would like to paste some text into a web browser element. For example:
private void pasteBtn_Click(object sender, EventArgs e){
WebBrowser1.PasteString("some text");
}
PasteString() Clearly doesnt exist but you get what i mean.
I have just tried pasting the string outright with a button, but the browser loses focues before it pastes.
I have tried many thing but none of them work.
Anything would help, i just wanna paste a string into a textbox on a website with a button, or something alike.
I think you need something like this:
N.B. not tested
private void pasteBtn_Click(object sender, EventArgs e){
var elemWithFocus = WebBrowser1.Document.ActiveElement;
elemWithFocus.SetAttribute("value", theStringToPaste);
}
Looking for a way to display a default value in a list box when launching the program e.g. the second the program is launched a default value is held and displayed in that list box until the user adds their own input?
Any ideas?
You can set a collection of items in the properties window at design time or you can add via code as shown here:
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("Default Value");
}
I am trying to copy values from one textbox to another textbox when user clicks a button. It seems to be a simple solution but for some reason when I click the coppyButton1 on the form, the value from uid1 (TextBox1) not getting copied into uid2(TextBox2). Hoping for feedback.
Code:
private void copyButton1_Click(object sender, EventArgs e)
{
uid2.Text = uid1.Text;
}
You can associate data to the clipboard incredibly easy:
Clipboard.SetText(txtCopyText.Text);
That would take the value of the textbox, then store to the clipboard.
protected void btnCopy_Click(object sender, EventArgs e)
{
// You would want to validate the contents of the textbox before copying.
if(!string.IsNullOrEmpty(txtCopy.Text))
Clipboard.SetText(txtCopy.Text);
}
If you simply want to force the value from one field to another, then the code you have above would force the value to be set. But to apply to the clipboard for copy and paste, you would do the above.
The only reason that code might not work would be if you don't have the textbox instantiated, or those fields are on another form that deviates from your btnCopy. Or you tabbed and allowed intellisense to reverse your copied data, ie one vs two. Your code:
ui2.Text = ui1.Text;
Is the field you thought you were copying from ui1.Text?
Update
To get data from the clipboard, you would do the following:
if(Clipboard.ContainsText(TextDataFormat.Text))
txtPaste.Text = Clipboard.GetText(TextDataFormat.Text);
I have Silverlight MVVMLight 4.0 application in which I have datepicker.
The datepicker is two way bound to the viewmodel. There is no code behind.
This works fine when tabbing of the datepickers textbox and will change the underlying property of the object.
But when I change the text box and don't tab off and click save the change is not registered.
I have looked at the various events that are fired and they don't fire unless you tab off
private void startDateDatePicker_TextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
{
}
private void startDateDatePicker_TextInputStart(object sender, System.Windows.Input.TextCompositionEventArgs e)
{
}
private void startDateDatePicker_TextInputUpdate(object sender, System.Windows.Input.TextCompositionEventArgs e)
{
}
private void startDateDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
}
Does anybody have a workaround for this?
kind regards,
Pat
I'm fairly sure that the TextBox needs to lose focus before the property is updated.
You could try handling the KeyDown event of the TextBox and update the property from there, but I'm not sure how well that would behave.
Change the UpdateSourceTrigger value in your binding.
If is not set, uses the default (which is the Lost Focus for TextBox.Text)
Depending the inner-workings and needs of your screen, you can set it to PropertyChanged or Explicit.
http://msdn.microsoft.com/en-us/library/ms752347.aspx
I'd like give focus to a textBox after a Tab has been selected but no matter what I try it doesn't work. I've looked at similar questions here but they don't get me the results I need. Here is what Ive tried.
private void tabBDERip_Click(object sender, EventArgs e)
{
textBoxPassword.Focus();
}
and
private void tabAll_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabAll.SelectedTab == tabBDERip)
{
textBoxPassword.Focus();
}
}
Can someone please tell me what I'm doing wrong?
Thanks
First thing the Click event of the TabPage control fires when the user clicks inside the TabPage not on the header so your SelectedIndexChanged event is the one you want to use.
I just tested code very similiar to yours:
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedTab == tabPage2)
{
textBox4.Focus();
}
}
And it worked fine.
Is the password textbox not enabled or something like that?
If you try to call Focus() on a different control does that also not work?
If you set a breakpoint inside the SelectedIndexChanged code does it get hit?
Update: Interesting. If the breakpoint isn't getting hit (before the if) I would double check that your eventhandler is properly attached. Look in your designer.cs for something like:
this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged);
Update: I put my working example at http://www.ccswe.com/temp/SO_TextBoxFocus.zip maybe looking at it will help you figure out where the issue is.
Update: The easier way to attach an event handler to a control on your form:
1: Select the Control to want to attach an event handler to and then click the Events icon (lightning bolt) in the Properties window.
alt text http://www.ccswe.com/temp/Attach_EventHandler_1.png
2: Find the event you want to attach to and double click to the right.
alt text http://www.ccswe.com/temp/Attach_EventHandler_2.png
3: A code stub will be automatically generated for you and the event will be attached in the designer.
alt text http://www.ccswe.com/temp/Attach_EventHandler_3.png
If you look at the properties window again you'll now see the name of the method that was generated.