WPF C#

03/24/2015 18:01 Hikarim#1
I am starting with WPF and have a question,...how do i make this:
if i click on an item TreeView that different items would be displayed in ListView, depended on what is selected in TreeView.

for example, in a mail application, if i click on inbox (TreeView), inbox messages should be listed in ListView, same for Sent,... etc..

If anyone could link me a good example that explains this, i googled but wasnt successful too much,...
03/24/2015 18:37 Mostey#2
You can do that with frameworks that use event piping such as [Only registered and activated users can see links. Click Here To Register...].
03/25/2015 12:42 Hikarim#3
what would be a good overall book to learn WPF? feel like i dont learn all that much in school :S
03/25/2015 13:47 Xio.#4
You don't need a 3rd party lib for that. Simply implement MVVM and done.

I'd suggest you to stop by at microsofts virtual academy, they have amazing stuff
03/25/2015 15:30 Hikarim#5
Okay, thanks i have a question though, with the OpenFileDialog,... for now we have to just add it to the menu so it shows up and add a filter to it (doesnt have to do stuff yet), but if i press cancel the whole application closes instead of just the OpenFileDialog,...
how can i fix that?

my code atm:
Code:
            OpenFileDialog odpri = new OpenFileDialog();
            odpri.Multiselect = false;
            odpri.Filter = "XML Files (*.xml)|*.xml";
            odpri.ShowDialog();
03/25/2015 19:47 Mostey#6
Quote:
Originally Posted by Xio. View Post
You don't need a 3rd party lib for that. Simply implement MVVM and done.

I'd suggest you to stop by at microsofts virtual academy, they have amazing stuff
Of course you don't need it but it would be advisable, though. Implementing the MVVM boiler plate code really isn't that great. I'd advise to only do that when learning how things work. Otherwise you really should work with frameworks that do handle much things easier and keep away the boiler plate.

By the way: How'd you do that if you seperate both ViewModels from each other? The ViewModel for the current inbox item needs to be parented to the ListView which actually doesn't make much sense. Event piping comes in really handy here because no composition is required.

Quote:
Originally Posted by Hikarim View Post
what would be a good overall book to learn WPF? feel like i dont learn all that much in school :S
Schools teach WPF? Guess that's out of my scope, I've never had teachers that have done more than the absolute basics of the basics.

Quote:
Originally Posted by Hikarim View Post
Okay, thanks i have a question though, with the OpenFileDialog,... for now we have to just add it to the menu so it shows up and add a filter to it (doesnt have to do stuff yet), but if i press cancel the whole application closes instead of just the OpenFileDialog,...
how can i fix that?

my code atm:
Code:
            OpenFileDialog odpri = new OpenFileDialog();
            odpri.Multiselect = false;
            odpri.Filter = "XML Files (*.xml)|*.xml";
            odpri.ShowDialog();
Where do you run that code? This code can't be the cause for this problem, except it is run in a cancel event or anything other that automatically closes the application after executing the function code.
03/25/2015 19:51 Xio.#7
Quote:
Originally Posted by Mostey View Post
.... I'd advise to only do that when learning how things work....
Now read his question again and tell me he's a professional.
03/25/2015 20:26 Hikarim#8
Nope, im not pro, i just had 1st lesson in school :)

the OpenFileDialog,... we just have to add it to the mebu in our app,... just so its tehre, no real use yet,...but when i run the app, and go to File->Open .. and then the OpenFIleDialog appears,... and if i click on ok or cancel, the whole application closes,...instread of just the OpenFileDialog

so i have it like this:
Code:
        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openit = new OpenFileDialog();
            openit.Multiselect = false;
            openit.Filter = "XML Files (*.xml)|*.xml";
            openit.ShowDialog();
            
        }
03/25/2015 21:15 Xio.#9
Quote:
Originally Posted by Hikarim View Post
Nope, im not pro, i just had 1st lesson in school :)

the OpenFileDialog,... we just have to add it to the mebu in our app,... just so its tehre, no real use yet,...but when i run the app, and go to File->Open .. and then the OpenFIleDialog appears,... and if i click on ok or cancel, the whole application closes,...instread of just the OpenFileDialog

so i have it like this:
Code:
        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openit = new OpenFileDialog();
            openit.Multiselect = false;
            openit.Filter = "XML Files (*.xml)|*.xml";
            openit.ShowDialog();
            
        }
PHP Code:
OpenFileDialog openit = new OpenFileDialog();

            
openit.Multiselect false;
            
openit.Filter "XML Files (*.xml)|*.xml";
DialogResult result openit.ShowDialog();
        if (
result == DialogResult.OK// Test result.
        
{
//Code if file was selected
        
}
//no file selected (pressed cancel) 
[Only registered and activated users can see links. Click Here To Register...]

^ Bookmark dotnetpearls, great stuff
03/26/2015 07:11 Mostey#10
Quote:
Originally Posted by Hikarim View Post
Nope, im not pro, i just had 1st lesson in school :)

the OpenFileDialog,... we just have to add it to the mebu in our app,... just so its tehre, no real use yet,...but when i run the app, and go to File->Open .. and then the OpenFIleDialog appears,... and if i click on ok or cancel, the whole application closes,...instread of just the OpenFileDialog

so i have it like this:
Code:
        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openit = new OpenFileDialog();
            openit.Multiselect = false;
            openit.Filter = "XML Files (*.xml)|*.xml";
            openit.ShowDialog();
            
        }
As I've said before, this code is not causing this behavior. There must be something other that closes/terminates the application if this event occurs. You should verify that by testing the OFD in another (blank) WPF project.