I have a list on images in a Pivot control. If you touch an image, it navigates to another view. If if flick through a new pivot and touch the image meanwhile, it navigates.
I noticed the Facebook app or the native photo albums don't have this bug.
Any idea ?
edit: the code :
Image img = new Image();
Delay.LowProfileImageLoader.SetUriSource(img, new Uri(adViewModel.Photos[k].ThbUrl));
img.Width = 150;
img.Tag = k;
img.Height = 150;
img.MouseLeftButtonDown += new MouseButtonEventHandler(launch_Diapo);
Grid.SetRow(img, i);
Grid.SetColumn(img, j);
PhotosGrid.Children.Add(img);
If you can show your code we can probably provide a more specific answer.
However:
I'm guessing you're using MouseButtonLeftDown or similar to detect the touching of the image. Rather than this, use the Tap gesture from the toolkit. This should prevent the issue you're having.
There is a possible alternative to disable the pivot gesture while you're touching the image, but depending on how you're using the image within the pivotItem this may end up preventing proper pivot navigation.
You can add the Tap event in code like this:
var gl = GestureService.GetGestureListener(img);
gl.Tap += new EventHandler<GestureEventArgs>(gl_Tap);
and the handler would be something like this. (but actually doing something useful-obviously.)
void gl_Tap(object sender, GestureEventArgs e)
{
MessageBox.Show("tapped");
}
Even I had a similar problem . What i did is ,check for MouseButtonLeftDown position and MouseButtonLeftUp position .If they are Equal navigate else do nothing .I will paste the code below.
Point temp;
void img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
temp = e.GetPosition(null);
}
void img_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Point point = e.GetPosition(null);
if (point == temp)
{
this.NavigationService.Navigate(new Uri(...));
}
}
Related
I'm new to Helix and liking it so far, I'm building a WPF app that loads the Helix viewport window inside a panel, I then instantiate a cube (CubedVisual3D) via a create button in WPF and it creates the cube, however when I go to click or drag/move it, it doesn't move around. How do I do this? Best approach?
example image
private void Helix_ViewPort_MouseDown(object sender, MouseButtonEventArgs e)
{
Console.WriteLine("Mouse down.");
Point mousePos = e.GetPosition(MyViewPort);
PointHitTestParameters hitParams = new PointHitTestParameters(mousePos);
HitTestResult result = VisualTreeHelper.HitTest(MyViewPort, mousePos);
RayMeshGeometry3DHitTestResult rayMeshResult = result as
RayMeshGeometry3DHitTestResult;
if (rayMeshResult != null)
{
MeshGeometry3D mesh = new MeshGeometry3D(); mesh.Positions.Add(rayMeshResult.MeshHit.Positions[rayMeshResult.VertexIndex1]);
mesh.Positions.Add(rayMeshResult.MeshHit.Positions[rayMeshResult.VertexIndex2]);
mesh.Positions.Add(rayMeshResult.MeshHit.Positions[rayMeshResult.VertexIndex3]);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
GeometryModel3D marker = new GeometryModel3D(mesh, new DiffuseMaterial(Brushes.Blue));
}
Console.WriteLine(result);
}
Please refer to the manipulator demo. There are many demos under helixtoolkit github source.
I have a BoxView that I want to change the color of when the user taps it. I created a BoxView called tapView and set the GestureRecognizer like so:
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (s, e) => {
// handle the tap
OnTapGestureRecognizerTapped(s, e);
};
tapView.GestureRecognizers.Add(tapGestureRecognizer);
and my method to handle the tap:
void OnTapGestureRecognizerTapped(object sender, EventArgs args)
{
var box = (BoxView)sender;
box.Color = Color.Red;
}
However this doesn't actually change the color on the Tap. Debugging and stepping through the code it does actually update the BoxView color in the code but not on the screen. What do I need to do to make this actually update the color when touched?
Try this solution, assuming you give your BoxView the following property in your XAML x:Name="myBox"
//This code betlow the page InitializeComponent call
var boxTapHandler = new TapGestureRecognizer();
boxTapHandler.Tapped += ChangeColor;
myBox.GestureRecognizers.Add(boxTapHandler);
Change color method, similar, though referencing the BoxView by name
private void ChangeColor(object sender, EventArgs args)
{
myBox.Color = Color.red;
}
So I discovered as standalone code this works ok, but in my MVVM app it does not. I wound up creating a box on top and changing the opacity on a tap worked just fine.
I have used below code to print the Panel of windows form.
private void button1_Click(object sender, EventArgs e)
{
System.Drawing.Printing.PrintDocument doc = new System.Drawing.Printing.PrintDocument();
doc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(Doc_PrintPage);
doc.Print();
}
private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
Panel grd = new Panel();
Bitmap bmp = new Bitmap(panel2.Width, panel2.Height, panel2.CreateGraphics());
panel2.DrawToBitmap(bmp, new Rectangle(0, 0, panel2.Width, panel2.Height));
RectangleF bounds = e.PageSettings.PrintableArea;
float factor = ((float)bmp.Height / (float)bmp.Width);
e.Graphics.DrawImage(bmp, bounds.Left, bounds.Top, bounds.Width, factor * bounds.Width);
bmp.Save("test12.jpg");
}
Now from above code, when i click on button the print function will be call but it excluded label in it. i am attaching image for your reference. first image is my UI design. , when i use print functionality it removes the label value as you can see in other image. i have used rectagleshap control which are in Pink color and i am displaying label on it. I think the label may be send back but when i used front back then also it is not appear.
Can you just try this one here i was using this for capture the whole screen which ever is active window its like screencapture or screenshot.
private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
Bitmap bitmap = new Bitmap(panel2.Width, panel2.Height);
Graphics graphics = Graphics.FromImage(bitmap as Image);
graphics.InterpolationMode = InterpolationMode.Default;
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
bitmap.Save(pathDownload + filename + ".jpeg", ImageFormat.Jpeg);
bmp.Save("test12.jpg");
}
In my case label was shown back to the rectangle, so i added one more label and set it as bring front. thanks for the help.
I am using Android.Support.V7.Widget.ListPopupWindow as a Drop-Down Menu from a Button within my layout. Here is the code snippet I am using
void MenuIcon_Click (object sender, EventArgs e)
{
popupWindow = new Android.Support.V7.Widget.ListPopupWindow (this);
popupAdapter = new MenuPopUpAdapter (this,selectedIndex,menuList);
popupAdapter.ItemClick+= PopupAdapter_ItemClick;
popupWindow.SetAdapter (popupAdapter);
popupWindow.AnchorView = menuButton;
Display display = WindowManager.DefaultDisplay;
Point size = new Point();
display.GetSize (size);
int width = size.X;
popupWindow.Width =160;
popupWindow.Show ();
}
But while debugging I noted that, even though I have given it a static width, it is rendered differently in different devices. What is causing this issue ?
This is because of the different screen densities in Android devices. You need to mention dimensions in DPs(Density Independent Pixels) to overcome this issue. This documentation from Google will be a nice read
You can get the corresponding pixel value to be mentioned while setting dimensions programatically from this method.
public int dpToPx(int dp) {
DisplayMetrics displayMetrics = Resources.DisplayMetrics;
int px = (int)Math.Round(dp * (displayMetrics.Density));
return px;
}
You may modify the code as above to fix the issue
popupWindow.Width =dpToPx(160);
I have to show a web browser inside a scroll viewer in windows phone application, with these requirements :
Web browser height should be adjusted based on its content.
Web browser scrolling should be disabled, ( when user scrolls within web browser, scrolling of scroll viewer should take place )
Web browser can do pinch-zoom and navigate to links inside its content.
How can I implement that? Any links or samples is greatly appreciated.
I'm using code like this. Attach events to the Border element in the Browser control tree (I'm using Linq to Visual Tree - http://www.scottlogic.co.uk/blog/colin/2010/03/linq-to-visual-tree/).
Browser.Loaded +=
(s,e)=>
{
var border = Browser.Descendants<Border>().Last() as Border;
if (border != null)
{
border.ManipulationDelta += BorderManipulationDelta;
border.ManipulationCompleted += BorderManipulationCompleted;
border.DoubleTap += BorderDoubleTap;
}
};
Further more the implementation I'm using is to prevent pinch and zoom, something you want to have working. Though this should help you in the right direction.
private void BorderDoubleTap(object sender, GestureEventArgs e)
{
e.Handled = true;
}
private void BorderManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
// suppress zoom
if (Math.Abs(e.DeltaManipulation.Scale.X) > 0.0||
Math.Abs(e.DeltaManipulation.Scale.Y) > 0.0)
e.Handled = true;
}
private void BorderManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
// suppress zoom
if (Math.Abs(e.FinalVelocities.ExpansionVelocity.X) > 0.0 ||
Math.Abs(e.FinalVelocities.ExpansionVelocity.Y) > 0.0)
e.Handled = true;
}
On Mark's direction, I used
private void Border_ManipulationDelta(object sender,
System.Windows.Input.ManipulationDeltaEventArgs e)
{
e.Complete();
_browser.IsHitTestVisible = false;
}