Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 28 11:35
    Albvadi closed #3727
  • Jan 28 11:35
    Albvadi commented #3727
  • Jan 28 10:58
    timunie commented #3727
  • Jan 28 10:53
    Albvadi commented #3727
  • Jan 28 07:57
    punker76 commented #3727
  • Jan 28 07:54
    punker76 commented #3728
  • Jan 28 07:04
    punker76 commented #3730
  • Jan 28 06:54
    batzen commented #3730
  • Jan 28 06:27
    e-karaulov commented #3730
  • Jan 27 20:43
    timunie commented #3730
  • Jan 27 17:00
    e-karaulov commented #3730
  • Jan 27 17:00
    e-karaulov commented #3730
  • Jan 26 22:04
    gitjsdr26 commented #3730
  • Jan 26 20:15
    punker76 closed #3730
  • Jan 26 20:15
    punker76 commented #3730
  • Jan 26 19:05
    timunie commented #3730
  • Jan 26 18:07
    batzen commented #3730
  • Jan 26 18:07
    batzen commented #3730
  • Jan 26 17:16
    gitjsdr26 commented #3730
  • Jan 26 13:20
    batzen commented #3730
Albvadi
@Albvadi

I followed the v4 HamburguerMenu with MVVM example from the code-samples and all it´s working correctly. But now, I need made global changes across from any view in the application and I don´t know what it´s the best form...

For example, in the About view in the viewModel, I have a button and I need to disable a element from the hamburguerMenu.
I thought to remove the readonly modifier here and make the changes directly in the mainViewModel...

It´s the correct way? There are better options to do this??

Twitter Tweets
@mrjakepavek_gitlab
did you make them static?
public static
Albvadi
@Albvadi
no, in the mainViewModel are public collections declared here
Twitter Tweets
@mrjakepavek_gitlab
yes in the viewmodel
did you declare the namespace?
Albvadi
@Albvadi
declare the namespace? don´t understand what you mean...
When I said "make the changes directly in the mainViewModel" I mean something like this:
Twitter Tweets
@mrjakepavek_gitlab
xmlns:view="clr-namespace:wpfapp.Views"
Albvadi
@Albvadi
in AboutViewModel.cs

public readonly MainViewModel _mainViewModel; // <-- remove readonly

public DisableElement(PropertyChangedViewModel mainViewModel)
{
    (MainViewModel)mainViewModel.MenuItems.GetItem(0).IsEnabled = false;
}
and yes, I´ve declared the namespace in the xaml
Tim
@timunie
Hi @Albvadi I use the ICommand-Interface if I want to disable or enable Buttons based on whatever
Albvadi
@Albvadi
Yes, I made this with Icommand, but my doubt it´s the method to access to the menu Items.. It´s the correct way remove the readonly modifier and setting directly in the mainViewModel from other viewModel?
Tim
@timunie
If it works, why not?
normaly ICommand has CanExecute and will disable the MenuItem if needed
Albvadi
@Albvadi
because the MVVM pattern... according to what I have read, each viewModel must have his own methods and properties and only set that, not set the properties from others viewModel
Tim
@timunie
Ok I am not a programmer by profession, so I try to do it this way, but sometimes I mix it up like you. If a real programmer would run away crying loud, I don't know :-) . I think it should be obvious what is going on and reliable . Then it would be OK from my point of view
Albvadi
@Albvadi

If a real programmer would run away crying loud, I don't know :-) .

:joy: :joy: :joy:

I think the same, I try to do the best, but it´s very frustrating when you arrive new to a new programmic language world and I ended mix it up to get working...
Tim
@timunie
@Albvadi can you show us a sample code or is it not public?
'''c#
public DisableElement(PropertyChangedViewModel mainViewModel)
{
(MainViewModel)mainViewModel.MenuItems.GetItem(0).IsEnabled = false;
}
'''
this is not ICommand
Here is a sample class for ICommand-implementation
    public class RelayCommand : ICommand
    {
        private Action<object> execute;

        private Predicate<object> canExecute;

        private event EventHandler CanExecuteChangedInternal;

        public RelayCommand(Action<object> execute) : this(execute, DefaultCanExecute)
        {
        }

        public RelayCommand(Action<object> execute, Predicate<object> canExecute)
        {
            this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
            this.canExecute = canExecute ?? throw new ArgumentNullException(nameof(canExecute));
        }

        public event EventHandler CanExecuteChanged
        {
            add
            {
                CommandManager.RequerySuggested += value;
                this.CanExecuteChangedInternal += value;
            }

            remove
            {
                CommandManager.RequerySuggested -= value;
                this.CanExecuteChangedInternal -= value;
            }
        }

        public bool CanExecute(object parameter)
        {
            return this.canExecute != null && this.canExecute(parameter);
        }

        public void Execute(object parameter)
        {
            this.execute(parameter);
        }

        public void OnCanExecuteChanged()
        {
            EventHandler handler = this.CanExecuteChangedInternal;
            if (handler != null)
            {
                handler.Invoke(this, EventArgs.Empty);
            }
        }

        public void Destroy()
        {
            this.canExecute = _ => false;
            this.execute = _ => { return; };
        }

        private static bool DefaultCanExecute(object parameter)
        {
            return true;
        }
Tim
@timunie
You can use it like a Property on your VM-Classes
Albvadi
@Albvadi

this is not ICommand

Was only an example how to access to the mainViewModelProperty.. I can prepare an example with the v4 hambuerguerMenu as the project base and using ICommand and discuss how to modify a global variable (or a menu item) from any view

Tim
@timunie
You don't need to, I was just wondering
Albvadi
@Albvadi
It is not a nuisance, It suits me very well to acquire knowledge and know how other developers solve these problems
I´ll do it tomorrow and I´ll ping you.. :)
sgamescz
@sgamescz
Hello everybody. Quick question about this.ShowMessageAsync("aaa", "bbb");. This works from main WPF form. but i want call showmessageasync from my viewmodels, which are displayed in main form thru hamburgermenu.
but this. , me. etc.. dont exist in views or in viewmodel.cs
MatthPicker
@MatthPicker_twitter
Hi everyone, I am using a HamburgerMenuItem for which I set the IsPaneOpen to a bool of my viewmodel. It works great. Now, I'd like to have this pane closed by default and have it open when the user hovers his mouse onto it. I can't make it work: the mouseEnter and mouseLeave events set on the HamburgerMenu.ItemTemplate node work only when you are on the actual label of the menu item, but not on the whole panel. Any idea? :-)
gandol2
@gandol2
hi
Tim
@timunie
@sgamescz use IDialogCoordinator (https://mahapps.com/controls/dialogs.html)
@MatthPicker_twitter you can try to create a Style and set a Trigger on IsMouseOver
(untested)
@gandol2 Hi
MatthPicker
@MatthPicker_twitter
Thanks @timunie . Is it possible to use ShowInputAsync with only one button (ok)
?
Tim
@timunie
Sorry, I don't know.
MatthPicker
@MatthPicker_twitter
thanks anyways :-)
Tim
@timunie
You can test it in the demo App
MatthPicker
@MatthPicker_twitter
I guess I have to create a custom message box dialog
simply surprised it does not come out of the box
Tim
@timunie
Yeah... freetime project, so the developer do what they need.
MatthPicker
@MatthPicker_twitter
did not mean to criticize, this is absolutely wonderful
thanks to everyone involved
I love playing with this and leaning WPF in the same time
learning
sgamescz
@sgamescz
@MatthPicker_twitter me too :-D i have same feeling ... thanks @timunie and other for helping us !
Tim
@timunie
@MatthPicker_twitter It was more meant as an explanation. Additions are welcome, if they fit into the design and API