MenuButton CanExecute Firing Wrong
-
I have a MenuButton on my Main Window toolbar:
Here's the DropDown button code:
public class DropDownButton : ToggleButton
{
public DropDownButton()
{
// Bind the ToogleButton.IsChecked property to the drop-down's IsOpen property
Binding binding = new Binding("Menu.IsOpen");
binding.Source = this;
this.SetBinding(IsCheckedProperty, binding);
DataContextChanged += (sender, args) =>
{
if (Menu != null)
Menu.DataContext = DataContext;
};
}public ContextMenu Menu { get { return (ContextMenu)GetValue(MenuProperty); } set { SetValue(MenuProperty, value); } } public static readonly DependencyProperty MenuProperty = DependencyProperty.Register("Menu", typeof(ContextMenu), typeof(DropDownButton), new UIPropertyMetadata(null, OnMenuChanged)); private static void OnMenuChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var dropDownButton = (DropDownButton)d; var contextMenu = (ContextMenu)e.NewValue; contextMenu.DataContext = dropDownButton.DataContext; } protected override void OnClick() {
-
I have a MenuButton on my Main Window toolbar:
Here's the DropDown button code:
public class DropDownButton : ToggleButton
{
public DropDownButton()
{
// Bind the ToogleButton.IsChecked property to the drop-down's IsOpen property
Binding binding = new Binding("Menu.IsOpen");
binding.Source = this;
this.SetBinding(IsCheckedProperty, binding);
DataContextChanged += (sender, args) =>
{
if (Menu != null)
Menu.DataContext = DataContext;
};
}public ContextMenu Menu { get { return (ContextMenu)GetValue(MenuProperty); } set { SetValue(MenuProperty, value); } } public static readonly DependencyProperty MenuProperty = DependencyProperty.Register("Menu", typeof(ContextMenu), typeof(DropDownButton), new UIPropertyMetadata(null, OnMenuChanged)); private static void OnMenuChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var dropDownButton = (DropDownButton)d; var contextMenu = (ContextMenu)e.NewValue; contextMenu.DataContext = dropDownButton.DataContext; } protected override void OnClick() {
And that's why I use user controls and "code-behind". Ship now or ship maybe. Why a "binding" instead of just a menu command parameter "constant" or "enum"? How many ways can you "add a company"?
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
And that's why I use user controls and "code-behind". Ship now or ship maybe. Why a "binding" instead of just a menu command parameter "constant" or "enum"? How many ways can you "add a company"?
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
Gerry Schmitz wrote:
And that's why I use user controls and "code-behind". Ship now or ship maybe.
Not sure what that means
Gerry Schmitz wrote:
Why a "binding" instead of just a menu command parameter "constant" or "enum"? How many ways can you "add a company"?
Binding? As opposed to....? Not sure what this response means. How else would this be done? I'm using a command that bound to the menu bars. If I understand what you're asking, I decided to use one command for all menu bars. This way I don't have to have a command and Execute/CanExecute for each bar.
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
Gerry Schmitz wrote:
And that's why I use user controls and "code-behind". Ship now or ship maybe.
Not sure what that means
Gerry Schmitz wrote:
Why a "binding" instead of just a menu command parameter "constant" or "enum"? How many ways can you "add a company"?
Binding? As opposed to....? Not sure what this response means. How else would this be done? I'm using a command that bound to the menu bars. If I understand what you're asking, I decided to use one command for all menu bars. This way I don't have to have a command and Execute/CanExecute for each bar.
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
For example:
CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
CommandParameter="{x:Static local:ActionId.NewCompany}"
Tag="company"
Header="New Company" />And "Tag" is your parameter. How many do you need? Or, menu click "sender" identifies the menu item. Your could even examine the "header"; or the "Name". A lot of "binding" for nothing, and only confusing for the next person.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
I have a MenuButton on my Main Window toolbar:
Here's the DropDown button code:
public class DropDownButton : ToggleButton
{
public DropDownButton()
{
// Bind the ToogleButton.IsChecked property to the drop-down's IsOpen property
Binding binding = new Binding("Menu.IsOpen");
binding.Source = this;
this.SetBinding(IsCheckedProperty, binding);
DataContextChanged += (sender, args) =>
{
if (Menu != null)
Menu.DataContext = DataContext;
};
}public ContextMenu Menu { get { return (ContextMenu)GetValue(MenuProperty); } set { SetValue(MenuProperty, value); } } public static readonly DependencyProperty MenuProperty = DependencyProperty.Register("Menu", typeof(ContextMenu), typeof(DropDownButton), new UIPropertyMetadata(null, OnMenuChanged)); private static void OnMenuChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var dropDownButton = (DropDownButton)d; var contextMenu = (ContextMenu)e.NewValue; contextMenu.DataContext = dropDownButton.DataContext; } protected override void OnClick() {
Why not pass the "tag" value as a commandparameter? Seems to me you should be using the enabled property when constructing the menu to manage access via the app security not the canexecute which logically only fires when the item is clicked!
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
-
Why not pass the "tag" value as a commandparameter? Seems to me you should be using the enabled property when constructing the menu to manage access via the app security not the canexecute which logically only fires when the item is clicked!
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
Can execute fires alot, like when the window refreshes. I want the b as r disabled BEFORE the user can click on it
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
Can execute fires alot, like when the window refreshes. I want the b as r disabled BEFORE the user can click on it
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
Your canexecute defines if the user can execute the menu item based on the users security profile (or am I missing something), why are you not disabling the menu item when you construct the menu, or don't even add the item if the user does not have permissions.
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
-
Your canexecute defines if the user can execute the menu item based on the users security profile (or am I missing something), why are you not disabling the menu item when you construct the menu, or don't even add the item if the user does not have permissions.
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
Constructing the menu happens once. The security profile can change at runtime, for example, the admin can grant access. I could force the user to log out and back in, but then I'd have to rebuild the UI to enable/disable things in response
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
Constructing the menu happens once. The security profile can change at runtime, for example, the admin can grant access. I could force the user to log out and back in, but then I'd have to rebuild the UI to enable/disable things in response
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
Kevin Marois wrote:
The security profile can change at runtime, for example, the admin can grant access.
I have supplied a function to refresh/change the user profile from the main landing page (mainwindow) without having to log off. I always use the constructor and disable items. So I'm no use to you with the CanExecute issue.
Kevin Marois wrote:
I'd have to rebuild the UI to enable/disable things in response
Now that on the other hand would be irritating.
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
-
I have a MenuButton on my Main Window toolbar:
Here's the DropDown button code:
public class DropDownButton : ToggleButton
{
public DropDownButton()
{
// Bind the ToogleButton.IsChecked property to the drop-down's IsOpen property
Binding binding = new Binding("Menu.IsOpen");
binding.Source = this;
this.SetBinding(IsCheckedProperty, binding);
DataContextChanged += (sender, args) =>
{
if (Menu != null)
Menu.DataContext = DataContext;
};
}public ContextMenu Menu { get { return (ContextMenu)GetValue(MenuProperty); } set { SetValue(MenuProperty, value); } } public static readonly DependencyProperty MenuProperty = DependencyProperty.Register("Menu", typeof(ContextMenu), typeof(DropDownButton), new UIPropertyMetadata(null, OnMenuChanged)); private static void OnMenuChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var dropDownButton = (DropDownButton)d; var contextMenu = (ContextMenu)e.NewValue; contextMenu.DataContext = dropDownButton.DataContext; } protected override void OnClick() {
Kevin Marois wrote:
The problem is that the CanExecute doesn't fire until I actually click on a menu bar.
As far as I can see, that would be the expected behaviour. The system doesn't need to know whether the menu item is enabled or not until the menu is shown, so I wouldn't expect it to call
CanExecute
for the menu's command until you click on the button to show the menu.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I have a MenuButton on my Main Window toolbar:
Here's the DropDown button code:
public class DropDownButton : ToggleButton
{
public DropDownButton()
{
// Bind the ToogleButton.IsChecked property to the drop-down's IsOpen property
Binding binding = new Binding("Menu.IsOpen");
binding.Source = this;
this.SetBinding(IsCheckedProperty, binding);
DataContextChanged += (sender, args) =>
{
if (Menu != null)
Menu.DataContext = DataContext;
};
}public ContextMenu Menu { get { return (ContextMenu)GetValue(MenuProperty); } set { SetValue(MenuProperty, value); } } public static readonly DependencyProperty MenuProperty = DependencyProperty.Register("Menu", typeof(ContextMenu), typeof(DropDownButton), new UIPropertyMetadata(null, OnMenuChanged)); private static void OnMenuChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var dropDownButton = (DropDownButton)d; var contextMenu = (ContextMenu)e.NewValue; contextMenu.DataContext = dropDownButton.DataContext; } protected override void OnClick() {
the CanExecute doesn't fire until I actually click on a menu bar.
[url=https://www.pornjk.com][color=#000000]pornjk[/color][/url] [url=https://www.porn800.me][color=#000000]porn800[/color][/url] [url=https://www.redtube.social][color=#000000]redtube[/color][/url]