Making a touch event bubble through an element in XAML - xaml

I have a canvas containing several smaller controls. If I drag my finger over them, they get selected. The ManipulationDelta or MouseMove events fire. All working fine.
But I want to display an image above these with a lower opacity. So I added a simple Image element.
My question is: Can I make it so that the image doesn't "steal" my events and that the element below the image gets all data. One image can cover several objects below so I cannot simply forward the event.
I can give you examples of where this is implemented on request, but avoid to publish it directly since it might be considered spam or advertisement.
Thanks

Set IsHitTestVisible property of the image to False.
From MSDN:
If this property is set to false, a UIElement will not report any
input events, such as MouseLeftButtonDown, and cannot receive focus. A
routed input event that was originated by a different object can still
route to or through an object in the object tree where
IsHitTestVisible is false. The object where IsHitTestVisible is false
can choose to handle that event, or can leave it unhandled so that it
routes further up the object tree.

Related

Why does moving controls between panels cause an exception in deferred render?

I am trying re-parent controls from one panel to another like this:
oldPanel.Children.Remove(control);
newPanel.Children.Add(control);
Which works fine with every control until i try to do it with the LAST child of the oldPanel, where i get:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Avalonia.Visuals
StackTrace:
at Avalonia.Rendering.DeferredRenderer.Render(IDrawingContextImpl context, VisualNode node, IVisual layer, Rect clipBounds)
The panels in question are 4 different StackPanels in a DockPanel and it only happens when moving controls between certain StackPanels.
If i only remove elements and don't add them to a new panel, the exception is never raised, this makes me think maybe i have to do something to fix the scenegraph before the next render? is there something like UIElement.UpdateLayout in wpf?
Some things I tried:
- setting oldPanel.IsVisible to false fixes this but i want these panels to still be visible because i have their minWidth set.
- calling InvalidateVisual InvalidateMeasure and InvalidateArrange on all the panels(including the dockpanel) and the control being moved.
- using ISetLogicalParent.SetParent.
Am I just doing this wrong? I couldn't find any examples online of re-parenting controls at all.

How to disable Sap Business One form's default resizing behavior?

I'm developing the custom UI layout system for our custom SBO forms. I.e. catching form's resize event and arranging the controls according to our specific layout logic. The problem is that, apparently, SBO tries to arrange controls according to its (clunky and primitive) logic on every form resize first! My code handling the resize event and rearranging the items works, but there is a noticeable performance delay, as items are essentially re-positioned twice on each form resize - once by SBO itself, and then by my code.
Is there any way to stop SBO arranging controls on our custom forms during resize, so that they will be positioned only once by my code (in the resize event handler)?
This page by Boyum IT helps to explain what the resizing rules are.
There's additional information on this page
To summarize those pages, every form is split into 4 quadrants, which are effectively pinned to the corners of the form that they belong to.
That means that as you resize the form, these quadrants separate from each other, leaving large sections of space between them.
I don't believe that there's an easy way to prevent this behavior out of the box, but you can manually override it using the B1 UI API, by setting the LinkTo property of the Items to match the ID of one of the Items in the top left quadrant, which causes the given item to move with the same behavior as that of the item specified in LinkTo.

How do I create an image button?

I'd like to display an image which acts as a button. This means that when I click on the image a mouseUp handler is executed.
image area does not have a mouseUp handler
the buttons seem not to have a property where I can assign an image to them.
You can add a mouseUp handler to an image's script, and it will be triggered when the image is clicked:
on mousedown
answer "hi"
end mousedown
You can give a button an image by setting it's "icon" property to the id of an image on the stack (you will generally then want to unset the 'opaque', 'threed', and 'shadow' properties in order to make it look pretty).
What David said.
Though "mouseUp" is introduced as a natural button-related handler, be aware that any object can have such a thing, including a field if it is locked, and there are even ways around an unlocked field as well. The important thing is to know that the language and its environment are far broader and richer than you might at first infer from the tutorials and lessons.
Craig Newman
You can assign icons to buttons. This solves all your problems at once.
Create a new image control, e.g. by importing an image using the File menu. Create a new button and set the icon of the button to the id of the image control. If you like, you can use another image control for the hilitedIcon of the button. Add mouseUp and mouseDown handlers to the button as desired.
If the image is too big, resize the button to make the image fit. Set the showName of the button to false or change the margins (something like 0,32,0,8) to move the text below the icon.

SL 4: ScrollViewer - RequestBringIntoView

How can I find the component in a ScrollViewer that handles the RequestBringIntoView event?
It isn't exposed on the two ScrollBar parts (not directly, anyway).
Thanks for any pointers...
UPDATE: Related: Can I get the ScrollContentPresenter part of the ScrollViewer? How?
Thanks --
Bigger picture:
We have a large Canvas contained in a ScrollViewer. At runtime, an arbitrary number of UserControls (I'll call them 'Blobs') are added to the canvas from the db. Their position and content come from the db. A user can 'select' a blob by clicking on it, and its appearance changes to indicate it is selected.
If the user uses a scrollbar to move the selected blob out of view, then clicks on another blob, the Canvas is scrolled so the previously-out-of-view blob is in view again. I assume this is due to some object raising the RequestBringIntoView, and the ScrollViewer is handling it.
Hope this makes sense...
Yet more info:
Added a handler (sb_ValueChanged) to the Scrollviewer's scrollbar ValueChanged event. Here's the stack from the mouse click that precipitates the scrolling:
OurControl.sb_ValueChanged() System.Windows.dll!System.Windows.Controls.Primitives.RangeBase.OnValueChanged() System.Windows.dll!System.Windows.Controls.Primitives.ScrollBar.OnValueChanged() System.Windows.dll!System.Windows.Controls.Primitives.RangeBase.OnValuePropertyChanged()
System.Windows.dll!System.Windows.DependencyObject.RaisePropertyChangeNotifications()
System.Windows.dll!System.Windows.DependencyObject.UpdateEffectiveValue()
System.Windows.dll!System.Windows.DependencyObject.SetValueInternal()
System.Windows.dll!System.Windows.DependencyObject.SetValue()
System.Windows.dll!System.Windows.Controls.ScrollViewer.InvalidateScrollInfo() System.Windows.dll!System.Windows.Controls.ScrollContentPresenter.VerifyScrollData()
System.Windows.dll!System.Windows.Controls.ScrollContentPresenter.ArrangeOverride()
System.Windows.dll!System.Windows.FrameworkElement.ArrangeOverride()
If only I could find out what the FrameworkElement that starts the mischief actually is...
Sorry... it doesn't seems to exist like it does in WPF. Check this link for a handy solution.
Update: Ok... for this you might need to walk the visual tree and some sort of recursive search need to be done. However, assuming you are using the default template for the scrollviewer as seen here, you can directly ask for the ScrollContentPresenter with something like this:
var BorderChild = VisualTreeHelper.GetChild(MyScrollViewer, 0);
var GridChild = VisualTreeHelper.GetChild(BorderChild, 0);
var ScrollContentPresenterChild = VisualTreeHelper.GetChild(GridChild, 0);

Picture box goes blank

In VisualBasic.Net When I activate a picture box and then draw something on it, it draws and then immediately goes blank. Works fine when I re-draw it, but almost always messes up the first time I draw on it. This has happenned with several different programs, and the help file is no help.
Try setting the DoubleBuffered property
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx
If that's not it, please provide more info.
Usually, if you're drawing something on a picture box or on another control, you have to take over the OnPaint event, and you're responsible of persisting what you draw on this event.
Thank you Andrew, but no help. I'm using .Net Framework 1.1, which does not offer the DoubleBuffered property... it was new in 2.0.
Not sure what additional info to provide.. the code is 300 lines long. When a button is clicked, the code expands my form, makes two picture boxes visible (one on top of the other (the back one is for some graph labels), and then uses some graphic brushes and pens to draw a graph on the front box. There's some database activity and calculations going on in the background at the same time.
I assume you're using the standard PictureBox component. Do you draw in the Paint-Handler? If not then the PictureBox will just erase your painted stuff next time it's asked to redraw itself (erase background etc.).
Yes, I believe I am using the standard picture box.
By Paint-Handler, I assume you mean a [Control].PaintEvent Handler. No I'm not using an event handler to do the drawing... drawing my chart is not an event in itself, but part of a much larger response to a button click event.
If you are saying that having the drawing code be part of a separate and specific handler can solve my problem, than I guess I could raise an internal event every time I want to redraw the chart. But I Would rather just figure out what is causing the PB to redraw itself without being told to.
If you cannot use the DoubleBuffered than you can HIDE a second picture box. You do the drawing in it and once it's completed you draw back to the VISIBLE one. This way the process of drawing is done on the hidden one and the white/flickering will not be shown.