Click here to Skip to main content
15,512,632 members
Home / Discussions / WPF
   

WPF

 
QuestionRefresh Attached Property? Pin
Kevin Marois7-Jan-20 11:17
professionalKevin Marois7-Jan-20 11:17 
AnswerRe: Refresh Attached Property? Pin
Richard Deeming8-Jan-20 2:18
mveRichard Deeming8-Jan-20 2:18 
QuestionWPF Exception - Send Error Report Pin
Kevin Marois30-Dec-19 8:41
professionalKevin Marois30-Dec-19 8:41 
AnswerRe: WPF Exception - Send Error Report Pin
Richard MacCutchan30-Dec-19 11:13
mveRichard MacCutchan30-Dec-19 11:13 
AnswerRe: WPF Exception - Send Error Report Pin
jimmson2-Jan-20 4:15
jimmson2-Jan-20 4:15 
AnswerRe: WPF Exception - Send Error Report Pin
Gerry Schmitz2-Jan-20 21:09
mveGerry Schmitz2-Jan-20 21:09 
AnswerRe: WPF Exception - Send Error Report Pin
Mycroft Holmes3-Jan-20 11:49
professionalMycroft Holmes3-Jan-20 11:49 
QuestionMenuButton CanExecute Firing Wrong Pin
Kevin Marois24-Dec-19 12:42
professionalKevin Marois24-Dec-19 12:42 
I have a MenuButton on my Main Window toolbar:
<menubtn:DropDownButton Grid.Column="2"
                        x:Name="btnAddItem" 
                        ToolTip="New Item"
                        Margin="2">

<pre>
<Image Height="32"
        Width="32" 
        Source="/Jayhawk.UI.WPF;component/Media/Images/new.png"/>

<menubtn:DropDownButton.Menu>
    <ContextMenu>

        <MenuItem x:Name="newCompanyButton" 
                    Command="{Binding NewItemCommand}"
                    CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
                    Tag="company"
                    Header="New Company" />

        <MenuItem x:Name="newProjectButton" 
                    Command="{Binding NewItemCommand}"
                    CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
                    Tag="project"
                    Header="New Project" />

        <MenuItem x:Name="newEmployeeButton" 
                    Command="{Binding NewItemCommand}"
                    CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
                    Tag="employee"
                    Header="New Employee" />

    </ContextMenu>
</menubtn:DropDownButton.Menu>



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()
    {
        if (Menu != null)
        {
            // If there is a drop-down assigned to this button, then position and display it 
            Menu.PlacementTarget = this;
            Menu.Placement = PlacementMode.Bottom;
            Menu.IsOpen = true;
        }
    }
}
Here's the VM code:
private ICommand _NewItemCommand;
public ICommand NewItemCommand
{
    get
    {
        if (_NewItemCommand == null)
            _NewItemCommand = new RelayCommand<object>(p => NewItemExecuted(p), p => NewItemCanExecute());
        return _NewItemCommand;
    }
}
and
private bool NewItemCanExecute()
{
    bool canExecute = true;

    if (SelectedTabView != null)
    {
        switch (SelectedTabView.ItemType)
        {
            case NavigationItemType.Employee:
                canExecute = AppCore.AppSecurity.HasAccess("add_employees");
                break;

            default:
                break;
        }
    }

    return canExecute;
}
The problem is that the CanExecute doesn't fire until I actually click on a menu bar.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: MenuButton CanExecute Firing Wrong Pin
Gerry Schmitz26-Dec-19 7:34
mveGerry Schmitz26-Dec-19 7:34 
GeneralRe: MenuButton CanExecute Firing Wrong Pin
Kevin Marois26-Dec-19 8:38
professionalKevin Marois26-Dec-19 8:38 
GeneralRe: MenuButton CanExecute Firing Wrong Pin
Gerry Schmitz27-Dec-19 6:58
mveGerry Schmitz27-Dec-19 6:58 
AnswerRe: MenuButton CanExecute Firing Wrong Pin
Mycroft Holmes27-Dec-19 15:21
professionalMycroft Holmes27-Dec-19 15:21 
GeneralRe: MenuButton CanExecute Firing Wrong Pin
Kevin Marois27-Dec-19 15:34
professionalKevin Marois27-Dec-19 15:34 
GeneralRe: MenuButton CanExecute Firing Wrong Pin
Mycroft Holmes27-Dec-19 15:48
professionalMycroft Holmes27-Dec-19 15:48 
GeneralRe: MenuButton CanExecute Firing Wrong Pin
Kevin Marois27-Dec-19 15:53
professionalKevin Marois27-Dec-19 15:53 
GeneralRe: MenuButton CanExecute Firing Wrong Pin
Mycroft Holmes27-Dec-19 16:20
professionalMycroft Holmes27-Dec-19 16:20 
AnswerRe: MenuButton CanExecute Firing Wrong Pin
Richard Deeming7-Jan-20 9:53
mveRichard Deeming7-Jan-20 9:53 
QuestionWPF Pin
MrsealIsHotChicken18-Dec-19 15:41
MrsealIsHotChicken18-Dec-19 15:41 
AnswerRe: WPF Pin
Gerry Schmitz19-Dec-19 8:11
mveGerry Schmitz19-Dec-19 8:11 
QuestionDataGrid Column Right Aligned Pin
Kevin Marois16-Nov-19 14:45
professionalKevin Marois16-Nov-19 14:45 
AnswerRe: DataGrid Column Right Aligned Pin
Mycroft Holmes16-Nov-19 21:07
professionalMycroft Holmes16-Nov-19 21:07 
AnswerRe: DataGrid Column Right Aligned Pin
Richard Deeming18-Nov-19 0:03
mveRichard Deeming18-Nov-19 0:03 
QuestionWPF C# Make window's the same width as the screen Pin
Acuena3-Nov-19 8:44
Acuena3-Nov-19 8:44 
AnswerRe: WPF C# Make window's the same width as the screen Pin
Richard MacCutchan3-Nov-19 22:45
mveRichard MacCutchan3-Nov-19 22:45 
AnswerRe: WPF C# Make window's the same width as the screen Pin
Richard Deeming3-Nov-19 23:28
mveRichard Deeming3-Nov-19 23:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.