Request NavigationView refresh from another part of form - vb.net

I'm a newbie with UWP coding. I've got a simple UWP app using VB.NET. Code behind a ContentGrid elsewhere on the same 'form' updates some settings that effect the NavigationView. How can I get the NavigationView to refresh?
I can't seem to reference it from one view to another
XAML snip of Navigation view:
<winui:NavigationView.MenuItems>
<winui:NavigationViewItem x:Uid="Shell_Main" Name="MainMenu" Tag="" Icon="Home" helpers:NavHelper.NavigateTo="views:MainPage" />
<winui:NavigationViewItem x:Uid="Shell_ContentGrid" Name="Video1" Tag="" Icon="GotoStart" helpers:NavHelper.NavigateTo="views:ContentGridPage" />
<winui:NavigationViewItem x:Uid="Shell_ContentGrid2" Name="Video2" Tag="\KES\" Icon="Slideshow" helpers:NavHelper.NavigateTo="views:ContentGridPage2" />
</winui:NavigationView.MenuItems>
<winui:NavigationView.PaneFooter>
<NavigationViewItem Icon="Help" Content="Help" Tag="User"/>
</winui:NavigationView.PaneFooter>
VB code behind the form/view to disable menu items in the OnLoaded event, works fine
For Each topic In navigationView.MenuItems
strDepends = topic.tag
bAllowed = Helpers.ContentAllowed(strDepends)
If Not bAllowed Then topic.IsEnabled = False
Next
Code on another view changes the settings, enabling a menu setting but I can't seem to tell the menu to refresh.
I'd like the NavigationView to refresh/repaint/whatever

Code on another view changes the settings, enabling a menu setting but I can't seem to tell the menu to refresh.
If we want to make NavigationView could update in other view, we pass the NavigationView instance to another view when call Navigate method. I found you have used VB UWP template studio, please refer the following code.
Private Sub OnItemInvoked(ByVal sender As WinUI.NavigationView, ByVal args As WinUI.NavigationViewItemInvokedEventArgs)
Dim item = navigationView.MenuItems.OfType(Of WinUI.NavigationViewItem).First(Function(menuItem) CStr(menuItem.Content) Is CStr(args.InvokedItem))
Dim pageType = TryCast(item.GetValue(NavHelper.NavigateToProperty), Type)
NavigationService.Navigate(pageType, navigationView)
End Sub
Other Page
Protected Overrides Sub OnNavigatedTo(ByVal e As NavigationEventArgs)
MyBase.OnNavigatedTo(e)
Dim nav = TryCast(e.Parameter, Microsoft.UI.Xaml.Controls.NavigationView)
If nav IsNot Nothing Then
For Each item As Microsoft.UI.Xaml.Controls.NavigationViewItem In nav.MenuItems
// update navigateview's status
Next
End If
End Sub

Related

How to hide context menu item when mouse out on grid

I am using windows forms with vb.net. This form has infragistics ultra win grid. with context menu item. The item name is "Delete Item". But when the user performs mouse out from grid i want to hide context menu item and when user hover back to the grid i want to show the context menu item. How can i do this.
Step 1) write code to handle the 'BeforeToolDropdown' event
example method signature:
Private Sub ultraToolbar_BeforeToolDropdown(sender As Object, e As
BeforeToolDropdownEventArgs) Handles ultraToolbar.BeforeToolDropdown
Step 2) this gets you a very important eventArgs object. Check to see if the click occurred in the Ultragrid
If IsNothing(TryCast(e.SourceControl, UltraGrid)) Then
Step 3) Finally you want to disable the PopupMenuTool
Dim p As PopupMenuTool = CType(utb.Tools("key"), PopupMenuTool)
p.InstanceProps.Visible = DefaultableBoolean.False
Note: in the example, the PopupMenuTool was located on an UltraToolbarsManager

Visual Basic PictureBox Panel Flicker

I am making a simple game that (for the main part) consists of a Panel with a grid of 32 PictureBoxes inside, each with a BackgroundImage. You click on a "tile" and it flips revealing a picture. My problem is that when the Form Loads, I can see it drawing. I see the Panel .. then empty PictureBoxes, then finally it fills in the PictureBoxes with the BackgroundImages.
I've turned DoubleBuffer to True for the Form, and I've also added the following:
Private Sub UseDoubleBuffer()
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
Me.UpdateStyles()
End Sub
Which I call when the Form Loads. I'm not sure what else I can do? I want it to just 'pop' onto the screen. Why isn't the DoubleBuffer working? Do I need to code the panel manually? I was trying to avoid that as it's obviously easier to just drag and drop into the Form, but if I need to, I will.
I can't post screenshots apparently, as my rep isn't high enough yet, but believe me, it looks hideous, and I do want to make this as sleek as I possible can. Any ideas?
Try creating flicker free custom panel controls:
Here are the steps to use this control:
1. Add new class "NonFlickerPanel" to your C# application.
2. Replace autogenerated class code with C# code shown below.
3. Use NonFlickerPanel object instead of Panel object in your application.
public partial class NonFlickerPanel : Panel
{
public NonFlickerPanel() : base()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint,
ControlStyles.UserPaint
ControlStyles.OptimizedDoubleBuffer,
true);
}
}
Try making the picture boxes invisible (.visible = false) until they're all loaded, then set visible to true for all of them.

animated GIF not working if Button is disabled

Just like what is said above, I'm having a problem regarding animated GIF. I have a button then if the button is clicked it show/display LOADING GIF within the button but I want that button not clickable while in the process of loading. So I use me.btn1.enabled = false but then the LOADING GIF is not working. What I mean is, it is visible but the ANIMATED LOADING GIF EFFECT not moving/working (or whatever you call that staff).
Thank you in advance!
Leave your button enabled but change the code behind so it ignores subsequent clicks if the loading process is underway. You could use a simple state flag for this.
Dim IsLoading As Boolean
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (IsLoading) Then
Return
Else
IsLoading = True
' Update button with loading GIF, do loading logic etc.
End If
End Sub
Obviously, you will need to reset IsLoading when your load is complete.
OR, hide the button when loading and show a PictureBox containing the loading GIF in its place.

Force UI redraw after loading new resource files

I have defined 2 themes (Resource files containing colours - .xaml), one in the resource dictionary on app load and one added on a button click by the following code:
Application.Current.Resources.MergedDictionaries.Clear()
Dim lightTheme As New ResourceDictionary()
Dim lightThemeUri As New Uri("/MyApp.UI;component/Assets/ColourResourcesLight.xaml", UriKind.Relative)
lightTheme.Source = lightThemeUri
Application.Current.Resources.MergedDictionaries.Add(lightTheme)
The colours in the new light theme are defined with the same key as the dark theme (loaded when app loads). My controls are then bound to this key with a staticResource.
After the new resource file loads i would like to somehow update / force a redraw of the whole UI to allow my new theme to display. This works on the controls contained in pages that i then navigate to, however it does not update my navigation bar (Main Page). Every other page is loaded into a container on the main page.
I would like the navigation bar to also update.
Was wondering what the best way to do this was, i have tried updating the bindings by using :
Public Shared Sub ForceControlRebind(cntrl As Control, depprop As DependencyProperty)
Try
Dim BindExp As BindingExpression = cntrl.GetBindingExpression(depprop)
Dim Bind As Binding = BindExp.ParentBinding
cntrl.SetBinding(depprop, Bind)
Catch generatedExceptionName As Exception
Throw
End Try
End Sub
However the BindExp always returns nothing.
I have also tried forcing a UI redraw by using:
mainpage.InvalidateMeasure()
mainpage.InvalidateArrange()
mainpage.UpdateLayout()
I know the resource file is properly loaded as the properties have updated when i step into the controls

Windows 8 appbar on selected item (like startup screen)

What I want to achieve in my application is the same as what windows did on their start up screen. When you select an item, open the appbar and show more items. When you just open te appbar when not selecting anything, don't show those items.
So far so good and it works like I want it to be. But there is some issue I can't solve. When you select an item on the start up screen, you can't close te appbar when right clicking anywhere on the screen. You have to deselect the item.
I just can't figure out how to disable that right click to close the appbar. Because then I am in a state where I have a selected item, but no appbar. I don't want that...
Thanks in advance!
There is a property called IsSticky
this can be used to stop you appbar from collapsing.
the other option you have is to hooking into Closed event and force it to re-open.
Based on the screen you provided aka the Metro UI :) i'd say that create a page that just hosts other tiles.
I have done a similar thing in one of my apps, have a look at
http://apps.microsoft.com/windows/en-gb/app/cineworld/7adfde16-33c3-4b51-b758-00366325288d
Have a look at Coding4Fun or Callisto
Set the AppBar property IsSticky="true" and handle the event RightTapped on your GridView/ListView, and in the event handler set e.Handled = true;
This will stop the rightclick/swipe routed event from reaching Page and it won't close the AppBar.
You could override the hide() function of the appbar and replace it with something like this:
appBar.hide = function () {
/// <signature helpKeyword="WinJS.UI.AppBar.hide">
/// <summary locid="WinJS.UI.AppBar.hide">
/// Hides the AppBar, if visible, regardless of other state
/// </summary>
/// </signature>
// Just wrap the private one
var listView = document.getElementById("yourListView").winControl;
var count = listView.selection.count();
if(count <1)
this._hide();
}
It's not a great workaround, but it works like a charm :)