Callisto + Pointer Pressed + xmal - windows-runtime

I´m using visual studio 2012
Hi I have tried every thing that has come in my mind to try and do this but I can´t find the anwser.
I tried this: mi1.PointerPressed() and it didn't work.
I tried a lot of ways and I din´t find in the callisto help something to explain how I put a command inside of the menuitem.
If some one know and can help me I will thank you so much. xD
Flyout flyOut = new Flyout();
flyOut.PlacementTarget = sender as UIElement;
flyOut.Placement = PlacementMode.Bottom;
Menu m = new Menu();
m.MinWidth = 110;
MenuItem mi1 = new MenuItem();
mi1.Text = "Some Option";
MenuItem mi2 = new MenuItem();
mi2.Text = "Another Option Here";
m.Items.Add(mi1);
m.Items.Add(new MenuItemSeparator());
m.Items.Add(mi2);
flyOut.Content = m;
flyOut.IsOpen = true;
Hi, How you show it´s one way, but a search more and I send a e-mail to developer and I found a best way using the callisto
private void ShowFlyoutMenu(object sender, RoutedEventArgs e)
{
Flyout flyOut = new Flyout();
flyOut.PlacementTarget = sender as UIElement;
flyOut.Placement = PlacementMode.Bottom;
Menu m = new Menu();
m.MinWidth = 110;
MenuItem mi1 = new MenuItem();
mi1.Text = "TE";
mi1.Tapped += mi1_Tapped;
m.Items.Add(mi1);
m.Items.Add(new MenuItemSeparator());
m.Items.Add(mi2);
flyOut.Content = m;
flyOut.IsOpen = true;
UpdateLayout();
}
private void mi1_Tapped(object sender, TappedRoutedEventArgs e)
{
/**YOUR CODE*/
}

It seems like the MenuItem doesn't handle traditional event-based code and you need to implement/use an ICommand implementation with the MenuItem. Two most common ones are RelayCommand from MVVM Light Toolkit and DelegateCommand from Prism. You can grab the DelegateCommand and its base class code from CodePlex, put it in your project and then you would then do something like this to use the MenuItem:
mi1.Command = new DelegateCommand(() => do something ...);

Related

AvalonDock: Keep floating windows visible when minimizing main application

Is it possibe to keep the floating windows visible when minimizing the main application?
Yes. the reason why it is being minimized is because the default owner of the floating window is the main window. so you have to set the floatingWindow.Owner = null; then you will also be able to put the main window in front of the floating window. if you want to switch between floating window and main window you can set floatingWindow.ShowInTaskbar = true;.
In my code i put it in a selectionChanged event handler so when i pop out a document it fires the selectionChanged event.
Document creation
private void userItem_Click(object sender, RoutedEventArgs e)
{
LayoutDocument ld = new LayoutDocument();
ld.Title = "All Users";
ld.ToolTip = "Manage all users";
//selection changed event
ld.IsSelectedChanged += Ld_IsSelectedChanged;
ld.IsActiveChanged += Ld_IsSelectedChanged;
Users users = new Users(ld);
ld.Content = users;
LayoutDocumentPane pane = ((todaysPayments.FindParent<LayoutDocumentPane>() ?? (panal.Children?[0] as LayoutDocumentPane)) ?? new LayoutDocumentPane());
pane.Children.Add(ld);
if (panal.ChildrenCount == 0)
{
panal.Children.Add(pane);
}
ld.IsSelected = true;
}
And the event handler
public void Ld_IsSelectedChanged(object sender, EventArgs e)
{
//get the floating windows from the DockingManager
manager.FloatingWindows.ToList().ForEach(floatingWindow =>
{
floatingWindow.Owner = null;
floatingWindow.ShowInTaskbar = true;
var fw = floatingWindow.Model as LayoutDocumentFloatingWindow;
floatingWindow.Title = fw?.RootDocument?.Title ?? "";
});
}

Using one ButtonStyle for more than one Button[Libgdx Scene2d]

I'm making an interface using Libgdx Scene2d, and I have more than one button which all require different style, this means I have to create one buttonStyle for each button?
btnStyle = new TextButton.TextButtonStyle();
btnStyle.up = btnSkin.getDrawable("boxBtn");
btnStyle.checked = btnSkin.getDrawable("boxBtn1");
btnBox = new Button(btnStyle);
anotherButton = new Button(newStyle?) //this is what I mean
Your thinking is correct. For each button that requires a different style, you will need a different TextButtonStyle.
TextButtonStyle styleOne = new TextButtonStyle();
styleOne.up = ...someDrawable1
TextButtonStyle styleTwo = new TextButtonStyle();
styleTwo.up = ...someDrawable2
TextButton button1 = new TextButton("Button1", styleOne);
TextButton button2 = new TextButton("Button2", styleTwo);
If you find that you are using the same set of styles over and over again, you could create static styles and use those for your buttons.
public class Styles {
public static final TextButtonStyle styleOne = new TextButtonStyle();
public static final TextButtonStyle styleTwo = new TextButtonStyle();
public static void initStyles() {
styleOne.up = ...
styleTwo.up = ....
}
}
Then call Styles.initStyles() when you've loaded your assets.
If you want to customize each style, but still use a set of default style attributes, you could try something like this:
public class Styles {
public static TextButtonStyle createTextButtonStyle(Drawable up, Drawable down) {
TextButtonStyle style = new TextButtonStyle();
style.up = up;
style.down = down;
style.font = Assets.getDefaultFont() //For example
style.fontColor = Assets.getDefaultFontColor() //For example
}
}
Then when you want to create a button, you can just do:
TextButton button = new TextButton("Text", Styles.createTextButtonStyle(drawable1, drawable2));
Hope this helps clear some things up.

How to add a dynamic PushPin to map in WP8.1

I'm currently trying to develop an simple application that allows user to add new pushpins. I'm currently using following code to add new pushpins,
Pushpin pushpin1 = new Pushpin();
pushpin1.GeoCoordinate = MyGeoPosition;
pushpin1.Content = "My car";
MapOverlay overlay1 = new MapOverlay();
overlay1.Content = pushpin1;
overlay1.GeoCoordinate = MyGeoPosition;
layer1.Add(overlay1);
myMap.Layers.Add(layer1);
But, to use this code, I need the latitude and longitude of the location that user has selected. So how can I get the latitude and longitude of the location that user has selected. (Simply geo-coordinate) I know I need to write a event handler, But I don't know the way that it has to be implemented... Thank you...
Try This
MapA = new Map();
MapA.Tap += MapA_Tap;
void MapA_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
GeoCoordinate location = MapA.ConvertViewportPointToGeoCoordinate(e.GetPosition(MapA));
//display pushpin by using location.latitude and location.longitude
}
There are multiple map events like
CenterChaged, MapTapped
you can handle those events to add your push pin. here is MapTapped example
async private void map_MapTapped(MapControl sender, MapInputEventArgs args)
{
var MyGeoPosition = args.Location;
//....
}

Draw route on Windows Phone 8 map as position changes?

Scenario:
I want a user to see a map and their current position. Then, if they click "start", navigation will begin and they'll see their "route" drawn onto the map as their position changes, similar to how some fitness apps work that map out your run/walk. The goal is to do this in real-time as the user's position changes.
Options:
The way I see it, there are two options: 1) use a RouteQuery and Map.AddRoute from the starting position, to the next position (when the position changes), keeping track of the last position, and always drawing a new MapRoute from that position to the new, or 2) displaying the user's current position as a dot that moves as their position changes, and then maybe when they press "stop", draw a MapRoute for each of their positions in order to show their full route.
I'd really prefer option #1 because the user can see their route progression, etc., as they go.
Here is the code that I'm using:
XAML:
<maps:Map x:Name="MainMap" />
<Button x:Name="btnStart" Content="Start"/>
<Button x:Name="btnStop" Content="Stop" IsEnabled="False"/>
Code-behind:
Global Variables:
GeoCoordinateWatcher watcher;
List<GeoCoordinate> listCoordinates;
GeoCoordinate lastCoordinate;
btnStart.Tap():
private void btnStart_Tap(object sender, GestureEventArgs e)
{
if (watcher == null)
{
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
watcher.MovementThreshold = 20;
watcher.StatusChanged += watcher_StatusChanged;
watcher.PositionChanged += watcher_PositionChanged;
}
watcher.Start();
}
watcher.StatusChanged():
private void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
switch (e.Status)
{
case GeoPositionStatus.Initializing:
btnStart.IsEnabled = false;
btnStop.IsEnabled = true;
break;
case GeoPositionStatus.NoData:
lblStatus.Text = "location data is not available.";
break;
case GeoPositionStatus.Ready:
lblStatus.Text = "location data is available.";
break;
}
}
watcher.PositionChanged():
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
if (listCoordinates == null)
{
// first time through:
listCoordinates = new List<GeoCoordinate>();
listCoordinates.Add(e.Position.Location);
lastCoordinate = e.Position.Location;
return;
}
else
{
listCoordinates.Add(e.Position.Location);
DrawRoute(e.Position.Location);
lastCoordinate = e.Position.Location;
}
}
DrawRoute function:
private void DrawRoute(GeoCoordinate newPosition)//
{
RouteQuery query = new RouteQuery()
{
TravelMode = TravelMode.Driving,
Waypoints = new List<GeoCoordinate>() { MainMap.Center, newPosition }
};
query.QueryCompleted += RouteQueryCompleted;
query.QueryAsync();
MainMap.Center = newPosition;
lastCoordinate = newPosition;
}
And finally, RouteQueryCompleted():
void RouteQueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
mapRoute = new MapRoute(e.Result);
MainMap.AddRoute(mapRoute);
}
What happens:
It appears to work for a second as I begin driving, a short line is drawn where my start position is, but then about 10 second in, a line is randomly drawn down a nearby street (probably equivalent to 3 or 4 blocks long) and then down another block on a side road (while the whole time I haven't even driven ONE block, let alone make any turns!). It's very bizarre and definitely not accurate. I can upload a screenshot to better illustrate it if need be.
Can anyone see what I'm doing wrong in my code or is there a better way to accomplish this? I wasn't sure if this was the best way but I wasn't able to find any examples suggesting otherwise.
I ended up using MapPolyLine to draw a line between the last GeoCoordinate and the new one.
MapPolyline line = new MapPolyline();
line.StrokeColor = Colors.Blue;
line.StrokeThickness = 15;
line.Path.Add(lastCoordinate);
line.Path.Add(pos);
MainMap.MapElements.Add(line);
I am not sure why you are using RouteQuery for your task. Generally, you use this when you want the map sdk to determine a route for you given a set of coordinates. In your case however, you always know where you are through PositionChanged event. It will be easier to plot directly on the map as you move.
Something like this
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) {
Plot(e.Position.Location);
}
void Plot(GeoCoordinate pos) {
var ellipse = new Ellipse();
ellipse.Fill = new SolidColorBrush(System.Windows.Media.Colors.Blue);
ellipse.Height = 15;
ellipse.Width = 15;
ellipse.Opacity = 25;
var mapOverlay = new MapOverlay();
mapOverlay.Content = ellipse;
mapOverlay.PositionOrigin = new System.Windows.Point(0.5, 0.5);
mapOverlay.GeoCoordinate = pos;
var mapLayer = new MapLayer();
mapLayer.Add(mapOverlay);
MainMap.Layers.Add(mapLayer);
}

How do you make a custom auto complete component in Flex?

I need to make an auto complete component in flex that fetches the auto complete results from a remote database using a webservice. I have the webservice and querying part worked out. I've already made custom components in action script by extending VBoxes. However I cannot figure out how to generate the popup window that is supposed to show under the text input in my auto complete text box.
Currently I am using something like
PopUpManager.addPopUp(popup, parentComponent);
My popup class extends VBox and it extends the createChildren method as follows
protected override function createChildren():void
{
for (var i:int = 0; i < results.length; i++) {
var itemC:UIComponent =
factory.getComponent(results[i]);
addChild(itemC);
itemC.addEventListener(MouseEvent.CLICK,
getClickFunction(i));
}
private function getClickFunction(index:int):Function {
return function (event:MouseEvent):void
{
selectedIndex = index;
};
}
Unfortunately when the webservice retrieves its results and addPopUp is called, nothing shows up.
Currently the factory.getComponent method is executing this code
public function getComponent(user:Object):UIComponent
{
var email:Label = new Label();
email.text = user.email;
var name:Label = new Label();
name.text = user.displayName;
var vbox:VBox = new VBox();
vbox.addChild(name);
vbox.addChild(email);
return vbox;
}
I think you ought to look for someone who has already implemented this. While your issue is probably related to not positioning and sizing the component before calling addPopup() even if we helped you solve that you still have a lot more work todo. (BTW call super.createChildren in your override or else bad things will happen). Anyway, check this out:
http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1047291
Finally I figured out how to use the List control and I stopped using a factory to generate components, instead I use the itemRenderer feature in the list control. I also used that to replace the custom popup class, and I added a positioning function to be called later. By combining these things I was able to get the drop down to display as expected. It appears that some components do not work well as pop ups.
Regardless, the working pop up code is
Inside my autocomplete component which extends HBox
dropDownList = new List();
dropDownList.itemRenderer = itemRenderer;
dropDownList.dataProvider = results;
dropDownList.labelFunction = labelFunction;
dropDownList.rowCount = results.length;
dropDownList.labelFunction = labelFunction==null ?
defaultLabelFunction : labelFunction;
dropDownList.tabFocusEnabled = false;
dropDownList.owner = this;
PopUpManager.addPopUp(IFlexDisplayObject(dropDownList), DisplayObject(this));
callLater(positionDropDownList);
Method in the autocomplete component (textInput is my text field)
public function positionDropDownList():void {
var localPoint:Point = new Point(0, textInput.y);
var globalPoint:Point = localToGlobal(localPoint);
dropDownList.x = globalPoint.x;
var fitsBelow:Boolean = parentApplication.height - globalPoint.y - textInput.height > dropDownList.height;
var fitsAbove:Boolean = globalPoint.y > dropDownList.height;
if (fitsBelow || !fitsAbove) {
dropDownList.y = globalPoint.y + textInput.measuredHeight;
} else {
dropDownList.y = globalPoint.y - dropDownList.height;
}
}
The position function was code that I borrowed from http://hillelcoren.com/flex-autocomplete/