Is it possible to determine the area on which a user clicked on a tile? Just like an image map in HTML. I would like to specify two buttons at an image tile and carry out different actions for each of them.
No. It is not possible to do this.
With respect of lauching your app, the tile works just like a shortcut on your PC desktop.
If you really need the behaviour you describe you'll have to create 2 applications - 1 for each launch action.
You can use something like this for every UI element.
private void ListBox_MouseEnter(object sender, MouseEventArgs e)
{
string pos= e.GetPosition(CanvasForLoop).X.ToString();
}
Related
I am making an app for windows phone 8.
On one of the pages of the app, I want to get the co-ordinates of the touch.
I tried searching on net but I got results related to games.
I want to know is it possible to get the position of touch on canvas/or any other component in a simple app.
If yes, plz guide me through it.
Hook up to Tap event of the Control, and use GetPosition of event args.
<Canvas Tap="HandleTap/>
private void HandleTap(object sender, GestureEventArgs e)
{
Point point = e.GetPosition(null);
}
I'm trying to make an editable control using the HTMLEditor ( I'd like a rich-text pane like Swing's JEditorPane or JTextPane but it seems I need to wait a couple of years for that ). I want to have the user type in text and the control grows to suit. I have tried catching an event when the scroll-bar appears and increasing the size until it disappears but I can't work out how to wait until the JavaFX thread has actually re-sized the control on its parent.
There's probably a better way to do it than that... any ideas? Any ideas how to reduce it if text is removed?
TIA Mike Watts
For the edit control, use a WebView with contenteditable set to true like this example or a customized HTMLEditor.
Interact with it using the Java/JavaScript bridge similar to this editor. You can script the WebView using JQuery. Run a Timeline which polls the edit control's text dimensions using a JQuery dimension query script and adjust the control size appropriately.
[side note: I've added this as an answer even though it is just the details from jewelsea's - I couldn't format the code when replying as a comment].
This is what has worked to a certain extent:
in the html of the WebView component, added a tag <div id='measured'> around all of the text blocks
added a handler to the WebView using setOnKeyPressed and that calls checkHeight()
private int lastOffsetHeight;
private void checkHeight() {
int newHeight = (Integer)webview.getEngine().executeScript(
"document.getElementById(\"measured\").offsetHeight;") + 14;
if (newHeight != lastOffsetHeight) {
lastOffsetHeight = newHeight;
webview.setPrefHeight(newHeight);
}
}
This is not too bad, main problem is that if all of the text is deleted then the WebView component deletes the div. As jewelsea mentioned, JQuery might be a better solution but I'll update this if I ever fix the problem of including the library ;-)
I would like to create an info message box in Windows Phone.
It should look like a single text message, that's shown on screen for X seconds, and I doesn't have any confirmation buttons
as MessageBox.Show() does. It would be used to show user some messages about the app progress, like "file download started",
or "preferences saved".
I've tried to create something like that, using Popup element, but it seems a bit different of what I want to
make.
With the popup I can create something like that
canvas.MouseLeftButtonUp += new MouseButtonEventHandler(popupCloseEvent);
For example, which closes this popup when user taps it.
or something similar. (Maybe can implement a timer there to close it after a few secs)
Are there better ways to create such thing?
You could use the either the Message Dialog or Overlay controls in the Coding4Fun toolkit.
Found here: http://coding4fun.codeplex.com/
They are really simple and easy to use controls.
Try this
In Xaml:
<Popup Tap="Popup_Tap"></Popup>
In code behind:
private void Popup_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
(sender as Popup).IsOpen = false;
}
I hope it helps.
I want upon selection to change the background color of the item, however i can't seem to find a way to do it.
I'm trying to use the code below but can't find the completion for it, and i need to set the colror to a custom one such as "#8e8e8e":
private void list_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (list.SelectedItem != null)
{
ListBoxItem a = sender as ListBoxItem;
//a.Background=
PhoneApplicationService.Current.State["test"] = list.SelectedItem;
NavigationService.Navigate(new Uri("/Detail", UriKind.Relative));
}
list.SelectedIndex = -1;
}
So i need to chnage the selected item background color to #8E8E8E from C# for simplicity because changing the states seems a bit complicated especially that all i need to do is change background color of the selected item.
Thanks in advance,
Although not recommend like Matt already pointed out you should be able to achieve this by using ControlTemplates and Visual States. Check out this article on windowsphonegeek to see how: Part 1 Part 2
Please let us know if you encounter any problems
You should look at the visual states for selected items if you wish to do this.
However, standard behaviour for Metro apps and recommended design best practices advise not to use colour to indicate selection in anythign other than the ListPicker.
Without seeing your app, how you're using the ListBox or the purpose of indicating selection it's hard to advise further though.
Hello is it possible to create an object that would function like a button?
Because I'm making a room management system for a hotel and the manager wants me to put a graphical representation of the rooms. I'm thinking it would be user friendly if I create an object that would represent the room e.g (rectangle) because I think it's too awful if I put many buttons in it. (it's too painful in the eyes).
The object should be clickable because when the user clicks or double clicks it. The room details would appear.
Thank you very much...
Yes, it is. All of the controls (as long as they inherit from Control, which basically all UI elements do) have a Click-Event, which you can register to so you get notified when it is clicked.
If you tell me if you are using WinForms or WPF I can give you an example of drawing a custom clickabel object.
You can either just set the size of a button to represent the room, or you can catch the Click event of any element you like to use to represent the room, for example a Panel.
You can also create a class that inherits from a control and implements some more features, that way it's easy to reuse it. Example:
public class Room : Panel {
// perhaps something to keep track of what room it is
private int _id;
// a constructor that sets the data that you need
public Room(int id) {
_id = id;
}
protected override OnClick(EventArgs e) {
// here you can handle the click
}
}
You create an object that would inherit from Control, and do custom drawing code using System.Drawing, It's a pretty simple task. With Control you're exposed to regular events like MouseDown, MouseUp, MouseEnter, MouseLeave, OnPaint, PaintBackground. These are events you're going to want if you add effects.