Animation is not stop when panning in UWP - c#

I have a two Panel both the Panel are in different ScrollViewer, I need to process the synchronous scrolling without animation, if I scrolled the second Panel the first Panelalso need to scroll with same HorizontalOffset without animation.
I have used the ViewChaning event of 2nd ScrollViewer and update the view of 1st ScrollViewer with the same HorizontalOffset, without animation.
Its works perfectly when I scrolled using mouse, if I scroll using touch(panning) the animation is occurs.
Please refer the code below,
private void ScrollViewer2_ViewChanging(object sender, ScrollViewerViewChangingEventArgs e)
{
this.scrollViewer1.ChangeView(e.NextView.HorizontalOffset, e.NextView.VerticalOffset, null, true);
}
How can I resole this issue, any one suggest on this?

Related

Scrollbar value not updating when using mousescroll

I am dynamically adding buttons to a FlowLayoutPanel, when I scroll using the mouse wheel on the panel the scrollbar value does not change however it still scrolls. When I click on the small arrow to force a scroll the value changes.
I want an event to trigger whenever the value of the scrollbar changes but can't seem to figure out how to, any help is much appreciated.
Probably an oversight by the authors. Not sure what you are doing with the scroll values, but you can just use the MouseWheel event to get the same scroll value:
void flowLayoutPanel1_MouseWheel(object sender, MouseEventArgs e) {
this.Text = flowLayoutPanel1.VerticalScroll.Value.ToString();
}

How can I prevent UI raycast from going through another Canvas?

I have a two canvas in a Scene and all Canvas are set to Screen Space mode camera render mode. The first Canvas is the main Canvas and has some buttons.The 'order in layer' property is 0.
The 2nd Canvas covers the whole area of the 1st Canvas . When you click some button on the first Canvas,the second Canvas will popup over the first Canvas (order in layer is 1).
The problem is that when I touch over 2nd canvas, the raycast also hit the 1st Canvas. How can I prevent the raycast from hitting the first Canvas while the 2nd Canvas (popup) is displayed on the screen?
If the second Canvas is a just a popup UI over the first one, you don't need to make it a Canvas. Make it a Panel instead. Select your first Canvas, right click then go to UI->Panel.You can also do this from GameObject->UI->Panel. Just make sure that your first Canvas is selected.
A new UI panel will be created inside the first Canvas. You can rename this to Popup panel then put all the UI components of the popup UI such as Buttons and Texts under the Popup panel. Use popupPanel.SetActive(true); to show the popup Window, and popupPanel.SetActive(false); to hide it.
Just drag the PopupPanel to the popupPanel slot in the script below, then you can use showPopup() and hidePopup() to control the popup panel.
public GameObject popupPanel;
void showPopup()
{
popupPanel.SetActive(true);
}
void hidePopup()
{
popupPanel.SetActive(false);
}
EDIT :
Make sure your popup Panel is at end of the canvas in hierarchy to make it render on top of everything else. This is the main idea of blocking interaction with others behind it.

Windows Phone Grid zIndex

I'm working on an application where I have a grid of buttons (can be various number of them). Atm I'm using a 4x4 Grid to place them and stretch them to size. The issue is that these buttons can be dragged around, and they should be hovering over the rest of the buttons while they are dragged. They can be also clicked, in which case they slowly hover over to another point on the screen.
The problem arises from the fact that Grid doesn't handle zIndex, and putting a canvas under the Grid wouldn't help. I'm not sure if having a canvas with absolute coordinates would work on different sized screens, and the buttons are also supposed to hover over other elements outside the grid as well (and the grid is in a pivot - the button has to hover over whatever is outside the pivot as well).
The question is if there is any way other than a canvas with zIndex, and if not, how can I achieve a proper Grid-like layout with a canvas.
UPDATE:
I'm using the following code to move the button:
private TranslateTransform dragTranslation = new TranslateTransform();
private void Button_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
if (dragTranslation.X + dragTranslation.Y > 100)
{
//ClickLock to avoid the tap event from firing
clickLock = true;
}
draggedButton.RenderTransform = dragTranslation;
dragTranslation.X += e.DeltaManipulation.Translation.X;
dragTranslation.Y += e.DeltaManipulation.Translation.Y;
}
Note that I've skipped parts such as reassigning dragTranslation in the ManipulationStarted event.

Canvas Click events in Silverlight when not over a UIElement

I have a canvas object and I am sprinkling fantastic controls all over it. I'm using a ScaleTransform object to scale the canvas so I can zoom in/out.
I have wired up the controls so that I can drag them around, and the drag and drop works well by using MouseLeftButtonDown, MouseLeftButtonUp, and MouseMove. Now, I want to work on enabling an event when I click only on the Canvas. When I read the docs for the canvas object, I see that the MouseLeftButtonDown event only fires when it's over a UIElement.
Occurs when the left mouse button is
pressed (or when the tip of the stylus
touches the tablet PC) while the mouse
pointer is over a UIElement.
(Inherited from UIElement.)
Unfortunately, I want the opposite behavior. I want to know when the mouse is clicked on the Canvas while the mouse pounter isn't over any controls. Since I'm new to Silverlight, I could be doing this the wrong way. Is there something I have overlooked? Am I going about this the wrong way? I'm looking for a little help, and perhaps a lot of direction.
I'm no Silverlight guru, but could you add a transparent UIElement to the Canvas, below all other UIElements, and use it to determine if the user has clicked outside of any of the other drag/drop-able elements.
You want to know when a click happens on the Canvas and isn't over other controls?
The most natural thing is to capture the Canvas's MouseLeftButtonDown. Inside of that event, take a peak to see where the click happened. Then peak at the UIElements under the click. I recommend you keep everything in absolute coordinates to keep things straight. Something like:
void Page_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Point p = e.GetPosition(null);
var elements = VisualTreeHelper.FindElementsInHostCoordinates(p, App.Current.RootVisual);
foreach (var element in elements)
{
//Figure out if you're over a particular UI element
}
}
I think you may be interpreting the documentation wrong. According to MSDN, Canvas itself is an implementation of a UIElement:
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Panel
System.Windows.Controls.Canvas
From my experience, and correct me if I'm wrong, MouseLeftButtonDown usually only fires for the top-most UIElement clicked. So if you implement MouseLeftButtonDown for your Canvas, it should only fire when the Canvas is clicked, and NOT when the buttons are clicked. I'd say try it out first.
In WPF, I think this would be easily solved by routed events. However, Silverlight didn't get this feature. You may want to check out VisualTreeHelper.FindElementsInHostCoordinates. This article covers it a little bit.
http://www.andybeaulieu.com/Default.aspx?tabid=67&EntryID=95

Anchoring a Windows Forms Tooltip to the mouse

I want to show a tooltip when hovering over a button and as long as the mouse is over the button the tooltip should follow the mouse. What is the correct way to achieve that?
When I add a MouseMove event that calls tooltip.Show(...) with the updated mouse position it flickers extremely, and also redraws the tooltip when the mouse rests. And if it is an OwnerDraw tooltip I can see the default system tooltip style "fighting" with the self-drawn tooltip.
Indeed, with .Net 2.0 the ToolTip object has been altered. Before 2.0, there were some inconsistency problems when the ToolTip text was changed while the ToolTip was active, or with some other situations.
Since 2.0, the Tooltip is hidden each time something happens what could affect the currently active Tooltip.
While this solved some problems, it now causes some events being fired right after e.g. a SetToolTip(), even if this function has been called from within this very event, resulting in an endless loop of ToolTip draw/hide until the mouse moves away from the ToolTip area.
My own workaround is to check whether the ToolTip is already the same and omitting the Set ToolTip() if so. (simply omitting the next event by a static flag as suggested above can cause problems as there is no guarantee that there will be a new event right after, e.g. if the mouse has just touched the ToolTip area and moved away already).
Also, using OnMouseHover just to display a Tooltip disables the internal timer functionality of the ToolTip component as well as causing many many unnecessary events and therefore wastes processor time. The Popup Event of the ToolTip component serves well as point of action.
In this special case, however, OnMouse Hover is necessary to track the mouse movement.
Anyways, altering the ToolTip position causes a complete redraw of the Tooltip and therefore flicker. This can be reduced for a motionless mouse by checking whether the mouse position has changed between two events.
Unfortunately, the ToolTip component has no way to change the position of the ToolTip adn is shown always relative to the current mouse position. So the only way to have it follow the mouse is to close and redraw it.
it MAY help to set the UseFading and/or UseAnimation properties to false so the flicker can be further reduced.
OK, this may be complete overkill, and probably not the best solution, but I think a fun little hack nonthless.
Basically, I'm drawing a ListView at the location of the mouse. Some code:
ListView v = new ListView();
public Form1()
{
InitializeComponent();
v.Items.Add("Foo");
v.Height = 30;
v.Width = 50;
this.button1.Controls.Add(v);
v.MouseMove += new MouseEventHandler(v_MouseMove);
v.BackColor = SystemColors.Info;
this.button1.MouseMove += new MouseEventHandler(button1_MouseMove);
}
void v_MouseMove(object sender, MouseEventArgs e)
{
v.Location = new Point(v.Location.X + e.Location.X, v.Location.Y + e.Location.Y);
}
void button1_MouseMove(object sender, MouseEventArgs e)
{
v.Location = e.Location;
}
I've noticed that when manually showing a tooltip with OnMouseHover, OnMouseMove gets called one more time after the tooltip is shown. As a hack, I've ignored the next OnMouseMove call immediately following the tooltip being shown (using a flag). Perhaps a similar phenomenon is occurring?

Categories

Resources