pop up with editable text in windows phone 7 - windows-phone-7

I want to give the privilage for the user to rename a file. For that When the user clicks on menu item 'rename'a pop up dialogue with and editable text box should show up with 'ok' and 'cancel' buttons? How can i implement it? Pls share the code if there are any.
Br,
Jinu

You can use the InputPrompt from the Coding4fun Tookit
The documentation is available on Codeplex: http://coding4fun.codeplex.com/wikipage?title=InputPrompt&referringTitle=Documentation
Calling it is straightforward:
var input = new InputPrompt();
input.Completed += InputCompleted;
input.Title = "Rename file";
input.Message = "Enter a new name for the file:";
input.Show();
Then you just have to retrieve the value in the callback:
private void InputCompleted(object sender, PopUpEventArgs<object, PopUpResult> e)
{
MessageBox.Show(e.Result);
}

Related

Prompts on top of popup windows in Xamarin and MAUI

I have discovered the limitation of displaying prompts when they are invoked from a popup window. Specifically verified with CommunityToolkit.Maui Popups.
Here's the details:
In the Map page I have this handler for the map clicked event:
void mapClicked(object sender, MapClickedEventArgs e) {
var pin = new Pin {
Label = "Here's where it is",
Location = e.Location
};
map.Pins.Add(pin);
}
I wanted to allow the user to edit the pin label when clicking on the it, like so:
pin.InfoWindowClicked += async (s, args) => {
string pinName = ((Pin)s).Label;
await DisplayPromptAsync("Enter new label", "enter new label");
};
However, this didn't work as no DisplayPrompt was shown. I tried running it in the main thread, to no avail either.
UPDATE. I've figured it out, see answer below.
The problem arises when attempting to bring up the prompt from a popup window. Evidently, one can't have a DisplayPromptAsync (or DisplayAlert for that matter) on top of a popup.
On a platform-specific level in iOS the error message reads:
Attempt to present <UIAlertController> on <Microsoft_Maui_Controls_Platform_Compatibility_ShellFlyoutRenderer> (from <Microsoft_Maui_Controls_Platform_Compatibility_ShellFlyoutRenderer>) which is already presenting <CommunityToolkit_Maui_Core_Views_MauiPopup>.

xamarin android (not forms) button tag

I need to pass some additional information with a button press. From what I could gather reading on the web I should use a button tag.
So far I have this
Button button = new Button(this);
button.Text = "Test Button";
button.SetBackgroundColor(Android.Graphics.Color.Black);
button.SetTextColor(Android.Graphics.Color.White);
button.Tag = "hello";
button.Click += ClickEvent;
And this is the handler:
public void ClickEvent(object sender, EventArgs e)
{
Android.Widget.Button button = (Android.Widget.Button)sender;
var test = button.Tag;
}
This works, but I need to be able to pass 3 ints of data. I have tried using an array but I have no idea how to read it in the handler as it comes back as a java.object.
Can anyone please push me in the right direction?

How to Disable Windows Phone 8 Keyboard buttons?

I'm working on windows phone 8 textBox where i just change the inputscope of the textbox to number/digits. Problem is there is no use of dot(decimal point) button in the textbox so i want to disable the dot button or when user click on that button it does not reflect in the textbox i need to input only numbers. So Please help me in this Problem as i'm beginner. Thanks a lot.
You can just attach to the TextBox.KeyDown event and set it to Handled = true when a . is inputed, like this:
private void MyTextBox_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.PlatformKeyCode == 190)
{
e.Handled = true;
}
}
The code for . is 190

how to get parent name of a context menu item?

I'm trying to get the parent name of a context menu item.
So I tried something like this on menuItem_click :
Button clikance = (Button)sender;
string ladyGaga = Convert.ToString(clikance.Content);
But it didn't work (invalid cast exception). thx for any help
i have use a different approach for getting the sender button of my context menu. i have made an event on the "hold_click"
where i have get back the content of the button in a public string
private void GestureListener_DoubleTap(object sender, GestureEventArgs e)
{
Button clikance = (Button)sender;
ButtonEnvoyeur = Convert.ToString(clikance.Content);
}
If you look in the debugger at the point where the exception is raised, you'll see that sender isn't a Button, so trying to do an explicit cast to Button will obviously throw an InvalidCastException.
You can use the VisualTreeHelper to walk up the tree from your actual sender to the Button element:
VisualTreeHelper.GetParent((sender as DependencyObject));
UPDATE: In your instance sender is the MenuItem in the ContextMenu. You can get to the parent ContextMenu from the MenuItem by using the VisualTreeHelper, but unfortunately, ContextMenu does not expose any public members that enable you to access the owner; the Owner property is internal. You could get the source code for the Toolkit and expose the Owner property as publi instead, or use a completely different approach.
Have you thought of using an MVVM framework (such as MVVM Light) to wire up commands to these context menu items? Your current approach is very fragile and will break as soon as you change the visual tree. If you used commands, you could pass any additional information that you need for processing via the command parameter.
Use the Tag property of the MenuItem to retrieve your Button :
// Object creation
Button myButtonWithContextMenu = new Button();
ContextMenu contextMenu = new ContextMenu();
MenuItem aMenuItem = new MenuItem
{
Header = "some action",
Tag = myButtonWithContextMenu, // tag contains the button
};
// Events handler
aMenuItem.Click += new RoutedEventHandler(itemClick);
private void itemClick(object sender, RoutedEventArgs e)
{
// Sender is the MenuItem
MenuItem menuItem = sender as MenuItem;
// Retrieve button from tag
Button myButtonWithContextMenu = menuItem.Tag as Button;
(...)
}
Alex.

OnClick on generated Textblock

Howdy,
I'm generating a bunch of Textblocks in a StackPanel. I would love to open another page when clicking on one Textbox:
sp.Children.Add(new TextBlock { Text = "Click me, I wanna open new content" });
How could I do that, it's probably something with "triggers" but I couldn't find anything on the web :-/.
Thanks!
You could use the Toolkit to add a gesture listener for the Tap event.
Alternatively you could use a HyperlinkButton as this contains a Click event.
Edit:
Example of using HyperlinkButton:
var sp = new StackPanel();
var hlb = new HyperlinkButton {Content = "click me"};
hlb.Click += hlb_Click;
sp.Children.Add(hlb);
ContentPanel.Children.Add(sp);
private void hlb_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/AnotherPage.xaml", UriKind.Relative));
}
Use TextBlock.ManipulationStarted event to detect a touch on it.

Resources