Skip to main content

Posts

File menu opening on wrong side? [Windows 10]

If you are using windows 10 and the file menu opens on the left side, here is a fix: Run (Win+R) paste the following: shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E} click "Other" tab choose "Left-handed" Now the menu should open within the window:

ContextMenu disabled at first?

ContextMenu has an issue that results in the menu being initially disabled. Regardless of whether what they are bound to is set to enabled or disabled. This will be true until a valid left click is done, usually on a button or the content it self. The root cause is that the ContextMenu is on a separate visual and logical tree than the window. This results in the items being disabled initially until a click is made first (not right click, but left click). Adding the following in the XAML to the menu item will resolve this issue: 1 <MenuItem Head... CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource AncestorType=ContextMenu}}" />

Updating UI during long operation

If you are performing an extensive operation that has multiple UI updates, for example in a loop, then you can use the following code to keep the UI updated alongside the operation. 1 2 3 4 5 6 7 8 9 10 private void UpdateUI() { DispatcherFrame update = new DispatcherFrame(); Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback( delegate ( object parameter) { update.Continue = false ; return null ; }), null ); Dispatcher.PushFrame(update); } Simply call that function inside your loop and the UI will update. Note, I have set the priority to background, you may have to set that to "Render"

ActualTop and ActualLeft after maximizing?

In wpf windows, maximizing the window can result to some funny scenarios. Window.Left and Window.Top actually don't get updated. I've looked around and a lot of people suggest using a pinvoke or reflection to get the updated values. I found that what is a little cleaner is to use the following, and it still gets the true actual  data Point ActualLeftActualTop = this .PointToScreen( new Point(0, 0));

Blank/White Image in WPF?

This is a bit of a short post, but in case you are adding an image to a WPF application and it is showing up as blank, make sure that the image is tagged as resource and not as content. Once this change is made, the image should display.

Monitor file system during software install

If you need to get details of what the system impact is from installing a specific program, you can use  InstallWatcher Pro . This software is relatively straight forward and to the point. It doesn't contain any bloatware. Usage is fairly simple. Click snapshot prior to installing the software, follow by analyzing after the installation to view file changes. You can also export the results to html and can then open the html in excel for filtering. Download

Want to cancel resize on a control?

If you are trying to cancel the resize event, it might be more difficult than you had imagined. A lot of the time you will find posts on stack overflow mentioning storing and restoring of the size before and after it resizes. I have two problems with that: 1) it isn't actually canceling the resizing 2) that is not what the user asked for Sadly, canceling the resize event isn't actually possible. At least not in the traditional sense. You can however, override the OnResize event of the control and then not   call the base. 1 2 3 4 protected override void OnResize(EventArgs e) { //base.OnResize(e); } This will for all intents and purposes, cancel the resize event. Even though one cannot cancel the resize event, or so I was told. Maybe you can... Maybe you can't, I don't know. But I bet it won't resize anymore!