Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
AnswerRe: PrintPreviewControl and HTML Pin
Luc Pattyn11-Jun-11 0:11
sitebuilderLuc Pattyn11-Jun-11 0:11 
GeneralRe: PrintPreviewControl and HTML Pin
MumbleB11-Jun-11 1:19
MumbleB11-Jun-11 1:19 
GeneralRe: PrintPreviewControl and HTML Pin
dSolariuM12-Jun-11 2:32
dSolariuM12-Jun-11 2:32 
GeneralRe: PrintPreviewControl and HTML Pin
dSolariuM12-Jun-11 2:33
dSolariuM12-Jun-11 2:33 
AnswerRe: PrintPreviewControl and HTML Pin
Luc Pattyn12-Jun-11 2:55
sitebuilderLuc Pattyn12-Jun-11 2:55 
GeneralRe: PrintPreviewControl and HTML Pin
BobJanova12-Jun-11 22:11
BobJanova12-Jun-11 22:11 
QuestionSuggestions On How To Refactor This Pin
Kevin Marois10-Jun-11 14:02
professionalKevin Marois10-Jun-11 14:02 
AnswerRe: Suggestions On How To Refactor This Pin
BobJanova12-Jun-11 23:44
BobJanova12-Jun-11 23:44 
That's not too bad. It looks similar but actually most of it is not identical and therefore isn't an immediate candidate for refactoring. The only thing that is is creating or activating a tab, which is about 10 lines, which isn't critical.

However, the type switching by name is ugly. You should have ClientModel and ProjectModel both implement an interface (let's call it IModelInfoProvider) that exposes what you need to determine tab identity (an AppViews enum, ModelType, and an ID). You could argue that they should go in the view model, so if you have two way linkage you could put them there and expose a base view model through the interface, or make the UI control have ViewModels not Models as its item list. Then you can do:

IModelInfoProvider item = (IModelInfoProvider)SelectedItem;

TabInfo tabInfo = getTabInfo(item.ViewType, item.ID);
if(tabInfo == null){
 TabInfo info = new TabInfo
 {
  ItemId = item.ID,
  ViewType = item.ViewType
 };

 IView view = ...;
 
 RadTabItem tab = addTab(view.DisplayName, view.IconPath);
 tab.Content = view;
 tab.Tag = info;

 SelectedTab = tab;
} else activateTab(tabInfo.Tab); // Why look it up twice? you already assigned it


Now, what goes in ... is essentially 'make your MV and View'. Depending on how strict on layering you're feeling you can either expose that as an interface method as well, or create a factory to which you can pass a model and it will construct views of the appropriate type. In the latter case you will still have to type switch, inside the factory code – please use is if you have to type switch, not string type names!
QuestionSaving changed data from a BindingSource Pin
tekturtle10-Jun-11 4:26
tekturtle10-Jun-11 4:26 
AnswerRe: Saving changed data from a BindingSource Pin
BobJanova10-Jun-11 6:05
BobJanova10-Jun-11 6:05 
GeneralRe: Saving changed data from a BindingSource Pin
tekturtle10-Jun-11 10:04
tekturtle10-Jun-11 10:04 
GeneralRe: Saving changed data from a BindingSource Pin
BobJanova12-Jun-11 22:14
BobJanova12-Jun-11 22:14 
GeneralRe: Saving changed data from a BindingSource Pin
tekturtle15-Jun-11 11:57
tekturtle15-Jun-11 11:57 
GeneralRe: Saving changed data from a BindingSource [modified] Pin
BobJanova15-Jun-11 13:20
BobJanova15-Jun-11 13:20 
Questionsetup - include driver installation Pin
lukeer10-Jun-11 2:10
lukeer10-Jun-11 2:10 
AnswerRe: setup - include driver installation Pin
Dave Kreskowiak10-Jun-11 3:05
mveDave Kreskowiak10-Jun-11 3:05 
GeneralRe: setup - include driver installation Pin
lukeer10-Jun-11 3:31
lukeer10-Jun-11 3:31 
GeneralRe: setup - include driver installation Pin
Dave Kreskowiak10-Jun-11 3:53
mveDave Kreskowiak10-Jun-11 3:53 
QuestionList Of DataRow Pin
om_metab9-Jun-11 22:50
om_metab9-Jun-11 22:50 
AnswerRe: List Of DataRow Pin
V.9-Jun-11 22:57
professionalV.9-Jun-11 22:57 
AnswerRe: List Of DataRow Pin
BobJanova9-Jun-11 23:47
BobJanova9-Jun-11 23:47 
AnswerRe: List Of DataRow Pin
Pete O'Hanlon10-Jun-11 0:13
mvePete O'Hanlon10-Jun-11 0:13 
GeneralRe: List Of DataRow Pin
om_metab10-Jun-11 0:35
om_metab10-Jun-11 0:35 
QuestionDetecting USB devices Pin
majamer9-Jun-11 21:46
majamer9-Jun-11 21:46 
AnswerRe: Detecting USB devices Pin
Kim Togo10-Jun-11 0:23
professionalKim Togo10-Jun-11 0:23 

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.