|
Change that line to:
var workspace = _mainWindow.Workspaces.FirstOrDefault(vm => vm.GetType().Equals(type));
|
|
|
|
|
Oh... DUH... you can't do the "is type" part because is expects an actual type, not a Type. How's that for confusing . I.e. you do blah is Window, not blah is window.GetType().
So you can either change it to:
vm.GetType() == type
Or go back to your generic method you had before and do:
vm is T
but with the above code, you need to do the vm.GetType() == type.
|
|
|
|
|
btw, you are missing a:
workspace = Activator.CreateInstance(type, new object[] { claimId });
|
|
|
|
|
Unfortunately making that changes causes an error.
An instance of type 'object' can not be assigned to a variable of type WorkspaeViewModel.
|
|
|
|
|
Ok, so you need the T casts
workspace = (T)Activator.CreateInstance(type, new object[] { claimId });
|
|
|
|
|
I needed that and also:
private void GoTo<T>(string viewModel, int claimId) where T: WorkspaceViewModel
However, this line:
Type type = Type.GetType(viewModel);
That returns null so everything else falls apart. How does it get a type from a string name? And can I pull out the string? It seems redundant since I am already giving it the type.
I can use T here:
var workspace = _mainWindow.Workspaces.FirstOrDefault(vm => vm is T);
and that gets rid of the need for type up until here:
workspace = (T)Activator.CreateInstance(type, new object[] { claimId });
Ayudame.
Cheers, --EA
Incidentally, without the "where T: WorkspaceViewModel I get an error on the workspace = (T)Activator... line.
|
|
|
|
|
Blargh.
For no apparent reason I had to use the fully qualified name.
So, the call looks like this:
GoTo<ClaimReportsViewModel>("litMan.ClaimReportsViewModel", _claimId)
Not sure why I have to do it that way, but it works. C'est la vie.
|
|
|
|
|
Lol, you keep switching between the two methods haha... now you are combining both of them... you should do:
GoTo<ClaimReportsViewModel>(_claimId)
Now you don't need the Type.GetType() line anymore. Your var workspace... line is correct. To fix the Activator.CreateInstance line, do:
workspace = (T)Activator.CreateInstance(typeof(T), new object[] { claimId });
Now you are using the generic method throughout .
|
|
|
|
|
I had a strong desire to get away from the mix and match, but I did not have the typeof(T) piece, I assumed you could just put the T in there and it did not work.
I tried Type.GetType(T) and T.GetType() to no avail. There are too many methods to find a type.
Regardless, thank you for the extensive help.
This is the final reslt:
public ICommand GoToECRsCommand { get { return new RelayCommand(() => GoTo<ECRsViewModel>(_claimId)); } }
private void GoTo<T>(int claimId) where T: WorkspaceViewModel
{
var workspace = _mainWindow.Workspaces.FirstOrDefault(vm => vm is T);
if (workspace == null)
{
workspace = (T)Activator.CreateInstance(typeof(T), new object[] { claimId });
_mainWindow.Workspaces.Add(workspace);
}
_mainWindow.SetActiveWorkspace(workspace);
}
Cheers, --EA
|
|
|
|
|
In my Goldlight[^] project, I have included a WorkspaceManager that might just be of help. Basically, any VM that needs to be treated as though it should be in a workspace inherits from WorkspaceViewModelBase (this provides things like the ability to close the particular workspace).
I then use this information to look the workspace up. Basically, the workspaces are maintained in an ObservableCollection and the UI binds to this.
It's all pretty simple to use. If you have any questions about the code, please feel free to ask.
|
|
|
|
|
I am using a Workspace viewModel right now that works as you have described. I can't recall where I got it, I think was an MSDN article from a year or two ago. Still, I will check out your framework is the workspace setup is a bit clunky, requiring a lot of defining throughout the project. Something more concise would be great.
Thanks for the heads up, I am always trying to find pieces like this.
Cheers, --EA
|
|
|
|
|
I just have to come back and say this framework is great. It is very feature rich. I am so deeply invested in the architecture right now (including MVVMLight) that I am apprehensive about switching over. There are a lot of tempting pieces though. This is definitely going to require some additional looking into.
|
|
|
|
|
Thanks. I wouldn't recommend switching over, Laurent did a really great job with MVVM Light - I mainly pulled it together to make it easy to combine MVVM with some of the things that you would typically use PRISM to do (as well as providing inbuilt support for theming). Please feel free to cannibalise it to your hearts content.
|
|
|
|
|
hi
I used the farsilibrary of code project but have error on my project,that namespace of Win does nor exist!
I add the dll of farsiLibrary and add FArsiLibrary.Win in my tools and drag the persiandatepicker on my form but when i want run my project it gets this error!I paste dll of all in my bin folder but nothin happen!
how can i solve it?
|
|
|
|
|
Ask this question in the forum at the bottom the article you got the library from.
You might also want to paste in the text of the error message you got. Just saying "it doesn't work" doesn't give enough information for anyone to help you.
|
|
|
|
|
Hi. I'm in need of recording video from a 4 channel DVR from .net C#. I've looked at EMGU a Opencv .net wrapper as well as the DirectShow .net library to do this. I've decided to give EMGU a go and is quite happy with it when using webcams. Now I want to use a 4 channel H.264 Usb DVR for the same purpose, but I don't know how to select a video channel on the DVR. When running the sample capture application of EMGU I only get a black screen. I have the same problem with DirectShow. It picks up the DVR as a DR 3101_3104 Video Capture device, but is also showing me the black screen.
Note that the camera is working fine, when I use "SuperDVR"(software that came included with the DVR).
I think there must be a way to specify the channel of which camera you want in both of these libraries, but I have no idea. Could someone shed some light on my problem please.
|
|
|
|
|
Does the DVR act as if it's a webcam? In other words, is what you are trying to achieve actually supported by the hardware? Can you play a DVD using the driver when you start a "webcam session" on MSN Messenger?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Hi all,
I am developing a windows application in which when i enter a ip address and click on submit button i want to list the details of all the ports which are opened in that ip address.
So please can you suggest me how can i do it ?
Thanks in advance.
|
|
|
|
|
sarang_k wrote: So please can you suggest me how can i do it ?
Research what a port-scanner is, how they work, and try to write some code.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Hey Guys,
Can any one suggest me how to create a NMAP application in c# ?
Thanks in advance.
|
|
|
|
|
sarang_k wrote: Can any one suggest me how to create a NMAP application in c# ?
Line by line.
What have you tried? Or are you just fishing for code?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
|
What does any of this have to do with using C# to identify whether or not a port is open?
|
|
|
|
|
Hello Guys,
i try to write an interactive Service which communicates with the Desktop.
The aim is to code a Service like Remote-Desktop.
I programmed an Application and it works great but now i wanna make a Service if the User isn't logged in or i i had to restart the computer.
This Article Create a system tray icon and a dialog for a Windows Service helped me to do this under Windows XP.
But if i try this Service on Windows 7 it doesn't work!
Have anybody an idea how i could do this?
The Service establishes a Network-Connection, makes Screenshots and send it to the Client. The Client can do User-Inputs which will be send to the Service and achieve on the machine.
|
|
|
|
|
The service and the UI-app need to be two distinct applications, with the service being GUI-less and the GUI being started when the user logs in.
I'd recommend TCP/IP communication to have those two communicate, using a listener in the Service and a client in the GUI-app. One of the benefits is that it allows for easy testing, it's easy to mock either side of the communication.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|