tabbed document interface in WPF using only on-board means?
Asked Answered
F

2

5

I've seen two threads here about TDI & C#. Both of them didn't really answer the questions I have ...

Since TDIs are pretty much like a standard nowadays, I can hardly imagine, that I have to buy a special control (like AvalonDock or SandDock). This must be possible with built in the tab-control(?) somehow! I don't need special features like dock- and draggable tabitems. Just open every form in a new tab. Thats it.

Like putting every forms content controls into user controls and by request (button, menu click ...) add a new tab and put the corresponding user control on it ... something like this.

How would you do it? This can't be THAT complicated (even for me) or am I missing something?!

thanks a lot!

Finochio answered 22/6, 2009 at 12:24 Comment(1)
well, which should I mark as answer? All 3 probably work - I currently try to figure out what Josh Smith is doing in this article posted by idursun. Its a very elegant solution, but kinda difficult to figure out for me as a beginner. What answers my actual question best is Josh G.'s post, I guess, so I'll mark his... Big thanks to all of you!Finochio
R
5

It's not that hard. It seems hard because there are a lot of different ways to do it.

Try this:

<TabControl x:Name="documentArea"/>

Handler for AddForm button:

private void AddFormClick(object sender, RoutedEventArgs e)
{
    object form = GetNewForm();

    documentArea.Items.Add(form);
}

That's it. You have to implement GetNewForm() in one of two ways. Have it return a user control that displays the form.

OR better yet, have it return your document that you want to display. Use a DataTemplate to select the controls to use for displaying this document. This method is going to be more complex to set up.

Rime answered 22/6, 2009 at 12:44 Comment(0)
K
7

Maybe Josh Smith's article on MVVM can give you an idea how to design such user interface. Example being built there is kinda tabbed document interface so you can use it as a starting block.

Khiva answered 22/6, 2009 at 12:28 Comment(4)
Be warned... Josh Smith's article is a great reference, but it is not simple to understand. You'll need a good handle on WPF's databinding to piece this together.Rime
Thanks, considering @mad9's previous questions I think he is getting closer to implementing MVVM :)Khiva
I'm all for that. MVVM is a great tool for WPF!Rime
Thank you very much, I already have the german version of the article ( msdn.microsoft.com/de-de/magazine/dd419663.aspx ) printed, right before me =)Finochio
R
5

It's not that hard. It seems hard because there are a lot of different ways to do it.

Try this:

<TabControl x:Name="documentArea"/>

Handler for AddForm button:

private void AddFormClick(object sender, RoutedEventArgs e)
{
    object form = GetNewForm();

    documentArea.Items.Add(form);
}

That's it. You have to implement GetNewForm() in one of two ways. Have it return a user control that displays the form.

OR better yet, have it return your document that you want to display. Use a DataTemplate to select the controls to use for displaying this document. This method is going to be more complex to set up.

Rime answered 22/6, 2009 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.