How can the Dispatcher-Property get null? - xaml

Windows 10 Build 10295/10332
Visual Studio 2015 Update 2
Problem
I have the strange case that the Dispatcher-property of a control, in my case a simple Button, gets null.
This Button is added at runtime by code whereas another Button is added in Xaml.
Both share the same Parent.
Codewise I interact with them in exactly the same way. But after 2-5 code-interactions (setting DependencyProperties like Style) the code-Button all of a sudden has a Dispatcher-value of null whereas the other is still set!
Both are still part of the visual-tree.
Question
How can the Dispatcher-value get null in the first place if both Buttons are treated equally?
Sideeffects
I suppose that this null-value leads to 2 exceptions I experience:
System.ExecutionEngineException when calling DependencyProperty.SetValue(...) or
System.AccessViolationException when using VisualTreeHelper.GetChildCount(...)

Related

Datagridview is all black on form load

I am using VB.Net is Visual Studio v16.6.3
I started getting this problem a few days ago on an application I developed two years ago and have been improving on and off. This error appeared out of now where. My DataGridView is OK at design time. when I launch the application, all forms that contain a DataGridView, it will appear all blacked out - as per image below.
If I minimize the form and return to it, the datagridview is fine, as per image below:
I get the same problem, in design mode or on a compiled executable. I have not tried this on some elses computer yet to see if it is graphics-card related or application related. Anyone has any idea how to resolve it? I did notice that if I move the datagrid binding and display from the "new" contructor to the "shown" event, it sometimes fixes the problem - but not always. Very weird and random.
I finally found it. I have to call the Refresh for my datagridview... I don't know why. Did not have to do that before but it works.
If someone can explain the reason behind this behavior, please tell me.

Nested SplitContainers bug the SplitterWidth

So I have 3 split containers, with 2 panels each.
SplitContainer1 is the main container that is docked in the Form ( Parent ).
SplitContainer1.Panel1 contains SplitContainer2 which is docked.
SplitContainer1.Panel2 contains SpliContainer3 which is docked.
So far so good.
SplitContainer1 has a SplitterWidth of 3.
SplitContainer2 and SplitContainer3 has a SplitterWidth of 6.
In the Designer, you can see the SplitterWidth difference between them, but when I build the solution, the SplitterWidth of SplitContainer2 and SplitContainer3 gets reset back to 4 no matter what I do. I have changed the code in "InitializeComponent" of the form with no effect.
The only way I got this working is in the Load Event of the form, re-specify the SplitterWidths which I find completely dumb. Why won't the SplitterWidths stay at the value I specified in the Designer?
If anyone can shed some light on this, what would be awesome!!
Thanks for your time,
Peter
Just so that this isn't left unanswered for eternity -
This is an old bug that has been in Visual Basic for many versions now, and is never addressed (nor is it likely to ever be addressed).
As Hans Passant mentions, the issue is due to the ISupportInitialize implementation for the SplitContainer.
Since it's a bug, there is not definitive way of resolving the issue that makes any logical sense.
One way, which I've tested in a mock up program, is as #xfx says - Add and manipulate the controls programmatically, rather than using the toolbox.
An alternative is to reload the SplitterWidths programatically, whether that's on Form_Load, which is most likely, or anywhere else in the code that it may be required.

Force VS to update initialization code

VS2008, VB.NET, Windows 7 Pro
I am creating a component to be dragged-and-dropped from the VS Toolbox onto
a developer's Form.
The component can display a UI at any time after it's Sited through which the developer can enter a value.
I would like to embed that value in an executable subsequently compiled by VS, so that the executable later "knows" that value.
If I put that value into a component Property, VS writes the value into the auto-generated Initialization code for the Form, which determines what gets embedded. VS does this reliably when it Sites the component.
It also does it when the developer adds a new Component to the Form, Deletes one, or changes a Property value with the VS PropertyBrowser.
But the value is not available until after Site, when VS has already completed its update, and I can't rely on Developers to do the VS UI work required to get VS to do it again. Does anyone know how to programmatically force VS to update the auto-generated Initialization code at a moment of my choosing in Designtime? (I.e. just after the developer uses my UI to set a value?)
Many thanks for your wisdom.

How to resolve Windows Forms designer issue - controls move on debug?

Is there a reason / fix for this weird designer issue (at least, I think it's related to the designer), whereby the controls on the form do not appear as they do in the design window when I debug the application..!
Please see the following two screenshots to demonstrate the problem (note: I have blacked out some of the content of the form, this is not the problem):
Picture 1: Showing how the form appears in the designer view
Picture 2: Showing how the form appears in debug mode
You can clearly see that some of the buttons have moved position on the form.
Note: At first glance, this may appear like a duplicate of: Windows Forms Designer destroys form layout. However, I have not installed any additional tools or components. This is simply a standard "vanilla" build of Visual Studio 2012 on Windows 7 32-bit.
I've also come across this question: UI Controls Overlapping & Fonts Issue in Windows Forms Application. However, I am not using "large fonts", nor am I using any non-standard fonts on my controls (all label and button text is left as default). Still, I can see how this would affect the control positions and will do some more checks in this area.
There's nothing happening within the form's Load method.
I'm also using TFS 2012.
What could be causing this? Is there anything I can do to fix it?
EDIT: I've removed the font property for each label and button control, allowing the system to set the default value. Still no change. Interestingly, if I open the form in design mode, then save it, then close it, then open it again, the buttons have moved... If I do this a few times, the buttons migrate until they're off the form.
OK, I've found the answer, after a bit more fiddling. It seems to be related to the Anchor property on the controls. I made a bunch of changes, testing between each change to see if there was any difference. When I selected all the controls and set the Anchor property to Top, Left, this solved the issue.
I hope this helps someone else at some point!

JavaFX 2 block mouse property

JavaFX 1.x had a blockinMouse property you could set to stop events propagating down to nodes below (for instance a right click to bring up a context menu when you'd just want it on the top node.)
I'm struggling to find an equivalent in JavaFX 2 though, I'm assuming it must be somewhere but the only things I've dug up online have been similar complaints, and I'd like to avoid the brute force style answer that's listed there.
Seems I was approaching this the wrong way - the solution was to simply call consume(); on the event in the top most node to stop the event propagating down to the lower nodes. The mouseTransparent property was similar but not what I was after, it just controls whether the node receives mouse events or just passes them on (similar to the old glasspane like approaches.)
In JavaFX 2 this is called: pointerTransparent.