I'm beginner to windows phone development and i done swiping the images in carousel view in portrait orientation and i tried for landscape orintation which is not done succesfully.please any one help me to resolve this issue.
TouchPoint _first;
private List<TList> _pivotList;
public Pivot()
{
InitializeComponent();
Loaded += pivot_Loaded;
Touch.FrameReported += Touch_FrameReported;
}
private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
TouchPoint mainTouch = e.GetPrimaryTouchPoint(null);
if (mainTouch.Action == TouchAction.Down)
_first = mainTouch;
else if (mainTouch.Action == TouchAction.Up)
{
var xDelta = mainTouch.Position.X - _first.Position.X;
var yDelta = Math.Abs(mainTouch.Position.Y - _first.Position.Y);
if (yDelta > Math.Abs(xDelta))
return;
if (Math.Abs(xDelta - 0) > 10)
{
var currentIndex = pivotList.SelectedIndex;
int noOfPivotItems = pivotList.Items.Count;
currentIndex = (xDelta < 0) ?
++currentIndex % noOfPivotItems :
(--currentIndex + noOfPivotItems) % noOfPivotItems;
pivotList.SelectedIndex = currentIndex;
}
}
}
here is code for DisplayOrientations .
public Pivot()
{
InitializeComponent();
Loaded += pivot_Loaded;
this.navigationHelper = new NavigationHelper(this);
Windows.Graphics.Display.DisplayInformation.AutoRotationPreferences = Windows.Graphics.Display.DisplayOrientations.Landscape;
Windows.Graphics.Display.DisplayInformation.AutoRotationPreferences = Windows.Graphics.Display.DisplayOrientations.PortraitFlipped;
}
Related
I'm trying to set swiping control for landscape orientation, for potrait orientation i'm using below code.Please help to work this in landscape orientation.
TouchPoint _first;
private List<TList> _pivotList;
public Pivot()
{
InitializeComponent();
Loaded += pivot_Loaded;
Touch.FrameReported += Touch_FrameReported;
}
private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
TouchPoint mainTouch = e.GetPrimaryTouchPoint(null);
if (mainTouch.Action == TouchAction.Down)
_first = mainTouch;
else if (mainTouch.Action == TouchAction.Up)
{
var xDelta = mainTouch.Position.X - _first.Position.X;
var yDelta = Math.Abs(mainTouch.Position.Y - _first.Position.Y);
if (yDelta > Math.Abs(xDelta))
return;
if (Math.Abs(xDelta - 0) > 10)
{
var currentIndex = pivotList.SelectedIndex;
int noOfPivotItems = pivotList.Items.Count;
currentIndex = (xDelta < 0) ?
++currentIndex % noOfPivotItems :
(--currentIndex + noOfPivotItems) % noOfPivotItems;
pivotList.SelectedIndex = currentIndex;
}
}
}
I have use WCF Services in an app.
I draw the line when going from 1 lists the coordinates returned from WCF. Then draw the wrong path. While Windows Phone 7 displays properly, using Polyline.
Shown below are the results that I got wrong:
And I want to display:
This is the code that I handle to draw:
void wcl_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
if (string.IsNullOrEmpty(e.Result) || e.Error != null)
{
MessageBox.Show("Lỗi kết nối! Hãy thử lại");
waitingPage.Visibility = System.Windows.Visibility.Collapsed;
return;
}
XuLyToaDo route = XuLyToaDo.TaoMapRoute();
//Lay ds diem ve
string Ketqua = XuLyToaDo.DanhSachDiemVe(e.Result);
string[] kq = Ketqua.Split('&');
//Lay thong tin toa do
XuLyToaDo routePushpin = XuLyToaDo.TaoMapRoute();
XuLyToaDo routePolyline = XuLyToaDo.TaoMapRoute();
//MessageBox.Show(kq[0]);
//MessageBox.Show(kq[1]);
//MessageBox.Show(kq[2]);
//Tao ds toa do
List<GeoCoordinate> lsToaDoPushpin = routePushpin.TaoDSToaDo(kq[0]);
List<GeoCoordinate> lsToaDoRoute = routePushpin.TaoDSToaDo(kq[1]);
// Lay ds ten duong
string[] MangTenDiaChi = routePushpin.TaoDSDuong(kq[2]);
if (lsToaDoPushpin == null)
{
MessageBox.Show("Không có thông tin");
waitingPage.Visibility = System.Windows.Visibility.Collapsed;
return;
}
for (int i = 0; i < lsToaDoPushpin.Count - 1; i++)
{
AddRoute(lsToaDoPushpin[i], Colors.Blue);
}
//ve duong di
for (int i = 0; i < lsToaDoPushpin.Count - 2; i++)
{
AddRouteMap(lsToaDoPushpin[i], lsToaDoPushpin[i + 1]);
}
//ve duong di
//MyRouteQuery = new RouteQuery()
//{
// TravelMode = TravelMode.Driving,
// Waypoints = lsToaDoRoute
//};
//MyRouteQuery.QueryCompleted += MyRouteQuery_QueryCompleted;
//MyRouteQuery.QueryAsync();
//Them danh sach tram
int k = 0;
foreach (GeoCoordinate geo in lsToaDoPushpin)
{
if (k == lsToaDoPushpin.Count() - 1)
break;
Pushpin pus = new Pushpin();
string str = "Direc_" + k;
pus.Template = Maps.App.Current.Resources[str] as ControlTemplate;
pus.Tag = k;
pus.Content = k.ToString() + ". " + MangTenDiaChi[k];
pus.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(pus_Tap);
MyMap.Layers.Add(new MapLayer()
{
new MapOverlay()
{
GeoCoordinate = geo,
PositionOrigin = new Point(0.5,0.5),
Content = pus
}
});
k++;
}
MyMap.Center = lsToaDoPushpin[0];
MyMap.ZoomLevel = 15;
waitingPage.Visibility = System.Windows.Visibility.Collapsed;
}
catch (Exception ex)
{
MessageBox.Show("Lỗi kết nối. Hãy thử lại!!" + ex.Message);
}
}
private void AddRouteMap(GeoCoordinate g1, GeoCoordinate g2)
{
List<GeoCoordinate> lsRoute = new List<GeoCoordinate>();
lsRoute.Add(g1);
lsRoute.Add(g2);
MyRouteQuery = new RouteQuery()
{
TravelMode = TravelMode.Walking,
Waypoints = lsRoute
};
MyRouteQuery.QueryCompleted += MyRouteQuery_QueryCompleted;
MyRouteQuery.QueryAsync();
}
void MyRouteQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
if (e.Error == null)
{
if (MyMapRoute != null)
AddlstMapRoute(MyMapRoute);
MyRoute = e.Result;
MyMapRoute = new MapRoute(MyRoute);
MyMap.AddRoute(MyMapRoute);
}
}
private void AddlstMapRoute(MapRoute maproute)
{
lsMapRoute.Add(maproute);
}
private void AddRoute(GeoCoordinate geo, Color color)
{
MyMap.Layers.Add(new MapLayer()
{
new MapOverlay()
{
GeoCoordinate = geo,
PositionOrigin = new Point(0.5,0.5),
Content = new Ellipse
{
Fill = new SolidColorBrush(color),
Width =5,
Height = 5
}
}
});
}
void pus_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
e.Handled = true;
Pushpin pus = sender as Pushpin;
ToolTipService.SetToolTip(pus, new ToolTip()
{
DataContext = pus,
Style = Application.Current.Resources["CustomInfoboxStyle"] as Style
});
MessageBox.Show(pus.Content.ToString(), "Thông tin trạm", MessageBoxButton.OK);
}
This is the place where I create database:
How can I fix this?
i guess its due to the fact that your travelmode is set to walking and google seems to think that walking there isnt allowed, so it takes the next possible way. try change the travelmode to driving or so.
greetings lars
I have a sort of drawing app. The lines are drawn on the touch input.
void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
int pointsNumber = e.GetTouchPoints(InkCanvas2).Count;
TouchPointCollection pointCollection = e.GetTouchPoints(InkCanvas2);
for (int i = 0; i < pointsNumber; i++)
{
if (pointCollection[i].Action == TouchAction.Down)
{
preXArray[i] = pointCollection[i].Position.X;
preYArray[i] = pointCollection[i].Position.Y;
}
if (pointCollection[i].Action == TouchAction.Move)
{
Line line = new Line();
line.X1 = preXArray[i];
line.Y1 = preYArray[i];
line.X2 = pointCollection[i].Position.X;
line.Y2 = pointCollection[i].Position.Y;
line.Stroke = StrokeColorBrush;
line.Fill = StrokeColorBrush;
line.StrokeThickness = StrokeWidth;
line.StrokeDashCap = PenLineCap.Round;
line.StrokeStartLineCap = PenLineCap.Round;
line.StrokeEndLineCap = PenLineCap.Round;
InkCanvas2.Children.Add(line);
preXArray[i] = pointCollection[i].Position.X;
preYArray[i] = pointCollection[i].Position.Y;
Brush aSolidBrush = new SolidColorBrush(Colors.Black);
}
}
Mouse events
void InkCanvas2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
currentPoint = e.GetPosition(InkCanvas2);
oldPoint = currentPoint;
}
void InkCanvas2_MouseMove(object sender, MouseEventArgs e)
{
currentPoint = e.GetPosition(this.InkCanvas2);
Line line = new Line() { X1 = currentPoint.X, Y1 = currentPoint.Y, X2 = oldPoint.X, Y2 = oldPoint.Y };
line.Stroke = StrokeColorBrush;
line.StrokeThickness = StrokeWidth;
line.StrokeStartLineCap = PenLineCap.Round;
line.StrokeEndLineCap = PenLineCap.Round;
line.StrokeLineJoin = PenLineJoin.Round;
this.InkCanvas2.Children.Add(line);
oldPoint = currentPoint;
}
I have done clear all by
InkCanvas2.Children.Clear();
now Im trying to implement a eraser function, then i draw over the line, it should erase those parts.
I tried changing color to transparent which does not do the trick. Any suggestions?
You can do something like this:
inkCanvas2.EditingMode = InkCanvasEditingMode.EraseByPoint;
I saw this code but it only works if the destination is specified by search!
I need to navigate to a specific position using latitude and longitude .
GeocodeQuery Mygeocodequery = null;
Mygeocodequery = new GeocodeQuery();
Mygeocodequery.SearchTerm = "Seattle, WA";
Mygeocodequery.GeoCoordinate = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude,MyGeoPosition.Coordinate.Longitude);
Mygeocodequery.QueryCompleted += Mygeocodequery_QueryCompleted;
Mygeocodequery.QueryAsync();
void Mygeocodequery_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
if (e.Error == null)
{
MyQuery = new RouteQuery();
MyCoordinates.Add(e.Result[0].GeoCoordinate);
MyQuery.Waypoints = MyCoordinates;
MyQuery.QueryCompleted += MyQuery_QueryCompleted;
MyQuery.QueryAsync();
Mygeocodequery.Dispose();
}
}
void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
if (e.Error == null)
{
Route MyRoute = e.Result;
MapRoute MyMapRoute = new MapRoute(MyRoute);
MyMap.AddRoute(MyMapRoute);
MyQuery.Dispose();
}
}
Here's a sample code (assuming you already have your source and target coordinates).
public partial class Foo : PhoneApplicationPage
{
List<GeoCoordinate> MyCoordinates = new List<GeoCoordinate>();
public Foo()
{
InitializeComponent();
}
private void SetMapCoordinates()
{
MyCoordinates.Add(new GeoCoordinate(Target.Latitude, Target.Longitude));
MyCoordinates.Add(new GeoCoordinate(Source.Latitude, Source.Longitude));
DrawMyRoute();
}
void MyRoute()
{
MyQuery = new RouteQuery();
MyQuery.TravelMode = TravelMode.Walking;
MyQuery.Waypoints = MyCoordinates;
MyQuery.QueryCompleted += MyQuery_QueryCompleted;
MyQuery.QueryAsync();
}
void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
if (e.Error == null)
{
Route MyRoute = e.Result;
MapRoute MyMapRoute = new MapRoute(MyRoute);
MyMapRoute.Color = (Colors.Blue);
MyLocMap.AddRoute(MyMapRoute);
#region Draw source location ellipse
Ellipse myCircle = new Ellipse();
myCircle.Fill = new SolidColorBrush(Colors.Blue);
myCircle.Height = 20;
myCircle.Width = 20;
myCircle.Opacity = 50;
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = myCircle;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = CoordinateConverter.ConvertGeocoordinate(SourceLocation);
MylocationLayer = new MapLayer();
MylocationLayer.Add(myLocationOverlay);
MyLocMap.Layers.Add(MylocationLayer);
#endregion
#region Draw target location ellipse
Ellipse CarCircle = new Ellipse();
CarCircle.Fill = new SolidColorBrush(Colors.Red);
CarCircle.Height = 20;
CarCircle.Width = 20;
CarCircle.Opacity = 50;
MapOverlay CarLocationOverlay = new MapOverlay();
CarLocationOverlay.Content = CarCircle;
CarLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
CarLocationOverlay.GeoCoordinate = CoordinateConverter.ConvertGeocoordinate(TargetLocation);
CarlocationLayer = new MapLayer();
CarlocationLayer.Add(CarLocationOverlay);
MyLocMap.Layers.Add(CarlocationLayer);
#endregion
MyQuery.Dispose();
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SetMapCoordinates();
}
}
I have made a timeline scrubber. It is working but I am facing a few problems.
When I click at the end of the track, the scrubber should go and stop at the end of the slider track but instead it goes to end of track, then jumps to to start of animation and replays the animation.
Scrubber does not move smoothly. It is kind of stuck. It does not move freely.
I have attached the fla file in case someone wants to see it. the link is http://www.mediafire.com/?cyk84zf0ndq6r. Could someone tell me where I am going wrong?
import flash.geom.Rectangle;
import flash.events.MouseEvent;
var barLength : Number = slider_mc.bar.width - slider_mc.scrub.width;
var rect : Rectangle = new Rectangle (slider_mc.bar.x, slider_mc.scrub.y, barLength, 0);
var moviePlaying:Boolean = true;
slider_mc.scrub.buttonMode = true;
slider_mc.scrub.addEventListener(MouseEvent.MOUSE_DOWN, this.scrubMouseDownHandler);
function scrubMouseDownHandler (event : MouseEvent) : void {
this.addEventListener("enterFrame",onEnterFrame);
slider_mc.scrub.addEventListener (MouseEvent.MOUSE_MOVE, this.scrubMouseMoveHandler);
slider_mc.scrub.addEventListener(MouseEvent.MOUSE_UP, this.scrubRemoveListenerHandler);
slider_mc.scrub.addEventListener(MouseEvent.MOUSE_OUT, this.scrubRemoveListenerHandler);
slider_mc.scrub.startDrag (false, rect);
}
function scrubMouseMoveHandler (event : MouseEvent) : void {
var spanPercentage : Number = (slider_mc.scrub.x - slider_mc.bar.x) / barLength;
var framePosition : int = int (animationMc.totalFrames * spanPercentage);
if (framePosition < 1) framePosition = 1 ;
slider_mc.bar.sliderFill_mc.scaleX = ((440/animationMc.totalFrames) * animationMc.currentFrame);
//trace (framePosition);
if (moviePlaying==true) {
animationMc.gotoAndPlay(framePosition);
//moviePlaying = false;
} else if(moviePlaying==false) {
animationMc.gotoAndStop(framePosition);
}
}
function scrubRemoveListenerHandler (event : MouseEvent) : void {
slider_mc.scrub.removeEventListener (MouseEvent.MOUSE_MOVE, this.scrubMouseMoveHandler);
slider_mc.scrub.removeEventListener(MouseEvent.MOUSE_UP, this.scrubRemoveListenerHandler);
slider_mc.scrub.removeEventListener (MouseEvent.MOUSE_OUT, this.scrubRemoveListenerHandler);
slider_mc.scrub.stopDrag ();
}
slider_mc.bar.sliderFill_mc.width = 0;
this.addEventListener("enterFrame",onEnterFrame);
function onEnterFrame(e:Event) {
//By default scrub keeps on moving along with animation at the start of swf, when it is published
//sl.value = this.currentFrame;
slider_mc.scrub.x = Math.floor((barLength/animationMc.totalFrames) * animationMc.currentFrame);
//it causes fill to scale along with scrub
slider_mc.bar.sliderFill_mc.scaleX((440/animationMc.totalFrames) * animationMc.currentFrame);
/////CURRENT TIME///
var currentSeconds = Math.floor(animationMc.currentFrame/24);
var CurrentInput = currentSeconds;
var timeElapsed = (CurrentInput > 3600 ? Math.floor(CurrentInput/3600) + ':':'') //hours
+(CurrentInput%3600 < 600 ? '0':'')+Math.floor(CurrentInput%3600/60)+':' //minutes
+(CurrentInput%60 < 10 ? '0':'')+CurrentInput%60; //seconds
//trace(timeElapsed);
currentTime.text = timeElapsed;
}
pause_btn.addEventListener(MouseEvent.CLICK, pauseAnim);
function pauseAnim(event:MouseEvent):void {
//this.removeEventListener("enterFrame",onEnterFrame);
moviePlaying = false;
animationMc.stop();
}
play_btn.addEventListener(MouseEvent.CLICK, playAnim);
function playAnim(event:MouseEvent):void{
this.addEventListener("enterFrame",onEnterFrame);
moviePlaying = true;
animationMc.play();
}
slider_mc.buttonMode = true;
slider_mc.useHandCursor = true;
slider_mc.bar.addEventListener(MouseEvent.CLICK, snapTo);
function snapTo(event:MouseEvent) {
slider_mc.scrub.x = mouseX;
//slider_mc.bar.sliderFill_mc.scaleX =((440/animationMc.totalFrames) * animationMc.currentFrame);
var spanPercentage : Number = (slider_mc.scrub.x - slider_mc.bar.x) / barLength;
var framePosition : int = int (animationMc.totalFrames * spanPercentage);
slider_mc.bar.sliderFill_mc.scaleX =((440/animationMc.totalFrames) * animationMc.currentFrame);
//trace (framePosition);
if (moviePlaying==true) {
animationMc.gotoAndPlay(framePosition);
//moviePlaying = false;
} else if(moviePlaying==false) {
animationMc.gotoAndStop(framePosition);
}
}
///better because it gives to leading zeros///////////
//TOTAL TIME///
var totalSeconds = Math.floor(animationMc.totalFrames/24);
var input = totalSeconds;
var totalAnimTime = (input > 3600 ? Math.floor(input/3600) + ':':'') //hours
+ (input%3600 < 600 ? '0':'') + Math.floor(input%3600/60)+':' //minutes
+ (input%60 < 10 ? '0':'') + input%60; //seconds
//trace(totalAnimTime);
totaltime.text = "/"+totalAnimTime;
the problem is your spanPercentage calculation near line 106. If you click close to the end, it can be a number > 1, giving you a framePosition that is greater than the frames in your animationMc.
Because you can't move a play head past the number of frames, it returns to the first frame.
The quick fix is to make spanPercentage = 1 if spanPercentage > 1. Below are the relevant lines.
function snapTo (event:MouseEvent){
slider_mc.scrub.x = mouseX;
//trace("mouseX: "+root.mouseX , slider_mc.scrub.x);
trace("animationMc.currentFrame: "+ Math.floor((barLength/animationMc.totalFrames)* animationMc.currentFrame));
//slider_mc.bar.sliderFill_mc.scaleX=((440/animationMc.totalFrames)*animationMc.currentFrame);
var spanPercentage : Number = (slider_mc.scrub.x - slider_mc.bar.x) / barLength;
trace("spanPercentage: " +spanPercentage);
if(spanPercentage > 1){
spanPercentage = 1;
}
var framePosition : int = int (animationMc.totalFrames * spanPercentage);
slider_mc.bar.sliderFill_mc.scaleX=((440/animationMc.totalFrames)*animationMc.currentFrame)
//trace (framePosition);
if (moviePlaying==true){
animationMc.gotoAndPlay(framePosition);
//moviePlaying = false;
}
else if(moviePlaying==false) {
animationMc.gotoAndStop(framePosition);
}
}
Your slider_mc instance was stretched on the stage from 440 to 574.
Returning it to it's proper size of 440 pixels wide fixes your funky scrubber.
Check it out in action and download:
http://micromedia.vaniercollege.qc.ca/home/nortonb/2011-12/flash2/stackoverflow/scrubber.htm