Search code examples
c#silverlightmvvmopenfiledialogchildwindow

How can I close OpenFileDialog by functions ok and cancel in MVVM pattern silverlight?


I saw a lot of different information on this theme but nothing helped me.

  1. How do u think? Probably better use a simpler pattern than MVVM with OpenFileDialog?
  2. I have 2 functions Ok and Cancel. Each one has (this.DialogResult = true) or (this.DialogResult = false). I must make it in MVVM pattern. I am using value -> (bool cls = true) right now and bind it to DialogResult = {Binding cls} and change this property in different functions but it doesn't work. I get some exception.

Do you know how I can solve this problem with closing OpenFileDialog?


Solution

  • create as method here is something that may get you along the lines of what you are looking for

        void OpenDialogAction(object param)
        {
            //Add code here
            OpenFileDialog d = new OpenFileDialog();
    
    
            if (d.ShowDialog() == true)
            {
                //set your variable true
            }
            else
            {
                //set your variable false
            }
        }