UWP commandbar more button not showing up with DynamicOverflowEnabled - xaml

I have a UWP app in which I am using CustomMediaTransportControls.
within those controls I've added some extra buttons within the commandbar PrimaryCommands and have set IsDynamicOverflowEnabled=true according to the docs it should automatically send the primary commands to the overflow menu when the screen size is not enough for all the buttons. and it should drop them out according to MediaTransportControlsHelper.DropoutOrder property on each appbarButton.
Problem
When screen size is less the controls seem to go into overflow menu as expected, but I cant access or see them because the More button is never visible, which is strange because I have tried to set OverflowButtonVisibility=visible and even tried it with Auto but that button never shows up on the UI. the fact that I know that primary commands are going to overflow is because I explicitly set the more button to visible, from within the templated style of the commandbar and then I see it in the UI, but its not ideal because it shows up even when it doesn't have anything in the overflow. so I changed it back to default binding value as it was before.
Also I am using re-templated style of the commandbar because I wanted to set the horizontalAlignment of the primary command buttons as center.
In this first image you can see all of controls are showing up
but here when I have resized the window to a smaller size I see less controls but no overflow menu ( more ) button.
Also note that app project has creators update as minimum target so DynamicOverflow should work because it was introduced in Anniversary update.
Update 1
In the picture below you can see I added a normal command bar to the page and it shows the more button even when there is no overflow buttons. obviously it is shown for the labels I guess.
and here you can see that upon resizing, the more button does get the extra buttons in it.
So the question is, why isn't it working with MediaTransportControls commandbar? I even tried default transportcontrols without any custom styling and just enabled all the buttons on it with is..buttonvisible and I got the same bug there as well. and which stage is this feature being prevented? and how can I override the behaviour?
With Live property explorer I can confirm that the visibility of more button is set to collapsed and if I set it to visible right there in property explorer I can see the button, now what I don't understand is why is it collapsed? even when I set overflowbuttonvisibility to visible in my xaml style?

After a lot of playing with my custom control I had to dynamically override the behaviour and create a little of my own behaviour in order to make this work.
I got following 2 controls in my Loaded event of the control
private void FluentMtc_Loaded(object sender, RoutedEventArgs e)
{
//secondaryItemControl to check how many items are in overflow menu
_secondarycontrols = (CommandBarOverflowPresenter)(((Popup)this.FindDescendantByName("OverflowPopup")).Child).FindDescendantByName("SecondaryItemsControl");
//to toggle visibility of more button
_moreButton = (Button)this.FindDescendantByName("MoreButton");
}
And I subscribed to DynamicOverflowItemsChanging event of the CommandBar within my OnApplyTemplate() method of my custom media transport controls.
protected override void OnApplyTemplate()
{
var barr = (CommandBar)GetTemplateChild("MediaControlsCommandBar");
//the event to control the dynamicoverflow automatically.
barr.DynamicOverflowItemsChanging += (s, e) =>
{
if (_secondarycontrols.Items.Count == 0 && e.Action == CommandBarDynamicOverflowAction.AddingToOverflow)
_moreButton.Visibility = Visibility.Visible;
else if (_secondarycontrols.Items.Count == 1 && e.Action == CommandBarDynamicOverflowAction.RemovingFromOverflow)
_moreButton.Visibility = Visibility.Collapsed;
};
//base implementation
base.OnApplyTemplate();
}
As you can see that within the event I dynamically check the number of items in secondayoverflow menu and control visibility of the more button accordingly. This is obviously a workaround, but if anyone find a proper reason as of why MediaTransportControls commandbar has this bug, please do post another answer on this post.
Also note that FindDescendent methods are coming from uwp community toolkit extensions nuget package.

Related

Having a problem with visual studio Databinding when leaving and coming back to the same form

For making this simply I have two forms a button on each to navigate between the two forms. Then on one I have a checkbox and label when the checkbox is checked it displays the label by using the following code in the form.load event:
Me.label1.DataBindings.Add("Visible", Me.checkbox1, "Checked")
The problem is if I were to leave the form with the checkbox and label and the checkbox is not checked and then I come back to the form with the checkbox and try and check it the label doesn't show up any suggestions or solutions.
Delete that line of code from the form load
Open your form in the designer, the one with the label and the checkbox on it
Click the checkbox
In the Properties grid expand (PropertyBinding) and open the drop down next to (none), click New at the bottom
Pick an initial value, and choose a name for the setting. Make it user scoped if you want to be able to save it and restore it next time the program opens
Now go to your label, properties, click the [...] next to (PropertyBinding) to see a list of all bindable properties, scroll to Visible and drop down to choose the same setting
Run the program.
Side note; when I did this I think I may have encountered a bug/feature of databinding (that I plan to research more) in that the behavior was only as expected if the bool starts out as true (so the control is visible) when the binding is set up. If the control is invisible, it never binds properly to see when the property has become true - so as a workaround (purely in this case where we're binding Visible), replace he call to InitializeComponent() with this, in the form's constructor:
if (!Properties.Settings.Default.FormatWithoutConfirmation)
{
Properties.Settings.Default.FormatWithoutConfirmation = true;
InitializeComponent();
Properties.Settings.Default.FormatWithoutConfirmation = false;
}
else
InitializeComponent();

VB.NET - Hiding Form on Load

So theres a few questions on this but they all give the same answer Me.Hide() which "works" if you count that when it loads, It will SHOW but then will hide seconds after which makes a weird Shadow-y-Laggy Effect.
Example:
(The small Window that shows and almost instantly hides is the window im trying to NEVER show)
Is there a way to actually hide the WHOLE form upon load? I know of the whole VisibilityCore method but with that I cant find a way to show it again at a later point.
So is there a way to hide it so it NEVER shows unless I tell it to Show?
Currently im using "Hide() combined with Form.Show Method".
If you set the form's Opacity property to 0 (through the Property Window) you shouldn't have this problem.
When you want to show the form (if it's going to be shown at all) just set the opacity back to 1.0.
Opacity is still a hack. The correct way is to not show it at all, versus making it invisible. To do this, don't make it the "Startup Object" at all.
On the Application tab of the Project Properties screen, there is a Startup Object setting. Create a Module with a Sub Main() and make that the entry point of your app by selecting it as the Startup Object instead of that little form that apparently doesn't do anything visual.
Maybe you have some initialization code in that starting form...move that to Sub Main.
you can minimize the form upon application launch.
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form fm = new Form1();
fm.WindowState = FormWindowState.Minimized;
Application.Run(fm);
}

Checkbox with image and autosize

In Word 2012 I have seen the following checkbox:
I am wondering if this checkbox is a .NET control with an image assigned to it (with property "imagealign" being middle right) or if this is a custom solution by MS for their Office GUIs.
I can reproduce the appearance, but I am unable to easily check if the user clicks the checkbox (and wants to change its state) or the info button and wants to show the tooltip.
Also, I have to add some spaces at the end of the checkbox text, else the image is under the text if the checkbox autosize property is set to True.
I would tend to think that the checkbox is a custom solution by MS or perhaps the image is a separate control.
Does anybody know more about this?
I think you are looking for
Checkbox.AutoSize = False
CheckBox.Image = "Your Image"
CheckBox.ImageAlign = MiddleRight
But this way you won't be able to distinguish if the user clicks the checkbox or the info button to show the tooltip.
As far as I know, there is no control available at .NET which allows this behavior, so I suppose they are using separate controls.
I think you'll need to use a PictureBox near the CheckBox and then use CheckBox_CheckedChanged and PictureBox_Click events to do whatever you want on each case.

VB.Net UI is missing

I'm using Visual Studio 2012 to make a Vb.Net application.
In short, I added DotNetBar RibbonControl with some RibbonItems on it as my menu.
What happened is one of my tab is suddenly missing along with all the buttons in it.
I have searched for it on my Document Outline still no luck.
But what even more odd is, when I tried to recreate it with the same name, it shows an Alert "Property value is not valid" with message "The name AppPOButton is already in use by another component".
When I checked it on the form's Designer I do found this lines:
Me.AppPOButton = New DevComponents.DotNetBar.ButtonItem()
and
'AppPOButton
'
Me.AppPOButton.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText
Me.AppPOButton.Image = Global.ProjectBMT.My.Resources.Resources.approval
Me.AppPOButton.ImageFixedSize = New System.Drawing.Size(40, 40)
Me.AppPOButton.ImagePosition = DevComponents.DotNetBar.eImagePosition.Top
Me.AppPOButton.Name = "AppPOButton"
Me.AppPOButton.SubItemsExpandWidth = 14
Me.AppPOButton.Text = "Approve"
Me.AppPOButton.Visible = False
and
Friend WithEvents AppPOButton As DevComponents.DotNetBar.ButtonItem
Is there anyone can explain why this is happening?
Thank you
This behavior is weird itself, but it's not a problem actually, All the Ribbon style works on "Containers", if you check your ribbon control and click the left-upper button will see these little arrows that move four containers, these objects hold the buttons, images and other controls. Within your design window in the right panel (Properties) you can still see the names of the controls you "lost" when you deleted your tab, wich is also a container.
Steps:
Add a container within your design view and Dock it into the Ribbon control Form.
Click on the uppper right boton (Right Arrow) and select "Layout Ribbon", this will adjust the lenght and hight of the controls conatained.
Add the tab that will contain all the controls you have.
The fact that they are still in the designer form is the prove that they still exist, This behavior is just a glitch in the position and order of the controls set above your form ;-)

Eclipse RCP : How to show message dialog after editor loads?

I am opening an editor from a view on click of a treenode. Now, when editor loads and controls are displayed to the user, I want to display a warning message dialog to the user based on certain values present on the editor.
I tried by putting the warning dialog at the end of createPartControl method of the editor. Dialog appears on double cliking the treenode as per the required functionality. But, the problem is that when the dialog appears, the controls on the editor are not yet visible. It's only when I close the dialog the editor controls are shown.
I want it to happen the other way around. i.e. The editor controls to show up first and then the warning dialog should appear. What changes should I do to achieve this effect?
You may want to call that MessageDialog in an asynchronous way, to leave the Editor the opportunity to complete itself, as suggested in this message.
show your warning dialog in an asyncExec() runnable would ensure that the editor's initialization all happens in the correct sequence.
So, something like (not tested) this code might do the trick:
getSite().getShell().getDisplay().asyncExec
(new Runnable() {
public void run() {
MessageDialog.openWarning(getSite().getShell(),"wrong","no)
}
});
}
Some other examples in this MapEditor class, where a MessageDialog is displayed through an asyncExec which waits for the result:
PlatformGIS.syncInDisplayThread