So, here's what I'm trying to do:
I'm making a game for practice using the GameStateManagement example from creators.xna.com.
The whole of the system is too much to explain here, so experience with the sample is kind of necessary.
The gist of it is that there are multiple game screens that overlay one another. One contains a board, overlayed above it is a few card images. The end goal is to be able to drag-and-drop the card image onto the table (or click it, the method isn't really the problem).
The actual question, then, is how can I pass data from one screen (the overlayed cards) to the other (the table).
I considered that it might be possible to create an event that gets fired when I drag-and-drop a card or click it or what have you, and then register an event handler on the other screen to handle it.
I, however, have pretty much no experience with custom events in C#. I'm not sure if all fired events go into a big "event pool" somewhere and handlers can pick them up regardless of where they are or how that works. I ask because the table screen and the overlayed screen are separate classes that both deal with drawing and updating, not with sending information around to one another.
Hopefully this is enough information to outline the problem decently. Any tips/advice are welcomed.
Thanks!
After some more experimenting, it looks like events are the way to go.
Without knowing the details of how events work, it seems that a fired event can be picked up from just about anywhere, so long as you register to receive it.
So, the solution to my problem was to create an "OnDrag" event in my "Hand Screen." Then to register to handle this event in the "Table Screen."
This resource helped me get going with the basic custom event handling: Writing C# Custom Events
Related
I am new to Windows 10 and I just came across Windows 10 new Outlook App which has swipe features but my requirement of swipe is different. I want to add 3-3 options on left and right side of ListView. I also came across below Nuget package from Github but it doesn't help much
SwipeListView
What I want to achieve is below
Please can someone suggest a good and easy way to add swipe actions in ListView.
As far as I know there is no library ready made for your need.
You can achieve the effect using custom ListViewItem. You will need a trick along the way to get the ListView accept TranslateX manipulation: Set ManipulationMode of the ItemsPresenter inside ListView template to TranslateX, System.
The rest is quite easy: you set manipulation mode of the custom ListViewItem to TranslateX, System, and handle ManipulationStarted, ManipulationDelta and ManipulationCompleted events. You also need to put UI underlay of the custom ListViewItem.
I can not give complete code sample given the big scope of your question. But you can take a loot at Comet to get the basic ideal of how to handle things.
There's no library that does exactly this, as far as I know. There are a few things that get close, however, and you could probably modify them for your needs. I'd recommend taking a look at this one. All you should need to do is slightly modify the template control, then set the control as the content of the ListViewItem.
However, it should be noted that having to tap the command pretty much defeats the purpose of being able to swipe the item; it would actually be faster for the user if you just used a button on the item which launches a CommandPopup. (Unless, of course, you do something really interesting and completely impractical and would launch whichever command they stop swiping on.)
After some research, I got a Nuget Package which meets my requirements
LLMListView
It has some very useful options as the following
Swipe Left/Right with one action
Swipe Left/Right with one action with animation
Swipe Right with fixed and multiple actions
Some extras
Pull to refresh
Pull with a button
Load More
Load More in Group view
Here is the screenshot
LLMListView Demo
I am in the process of recreating a Win32 (Delphi 5) screen using WPF in C# with the MVVM pattern. The purpose is to create a demo that I can use to push my company to make the move from Delphi 5 to C#. In this demo I want to do things the "right" way so we have a good example to start with. With that in mind, I am trying to adhere to MVVM as strictly as possible which is where I am currently running in to a problem.
In the original program/screen we have lookup dialogs that we can attach to edit boxes and grid cells. The way it works is that the lookup dialog is an implementation of a specific search (i.e. Customer lookup). When you attach the lookup dialog to a control, it listens to the key press events for the control. It has a progressive search feature so that when you start typing, if it can find results that start with what you are typing it will insert the first result in control you attached it to. While doing this it keeps the cursor where you were typing and highlights the part of the data that you typed in so that if you keep typing it can narrow down the results to find the more specific answer you were looking for. Where the dialog part comes in to play is when you hit the ellipse button next to the control or if you type in something that it couldn't find while doing the progressive search. In either of those cases it will bring up the lookup gui which will show you all the possible results, provide filters to help you narrow your search down etc. This gui is visually attached to the control you assigned it to. It always pops up right under the cell or edit box etc that you assigned it to.
So this lookup dialog is throwing me off when it comes to trying to figure out how to implement it using MVVM. So far my code mostly pure as far as MVVM goes. The only code in the Views code behind is the one line creating the ViewModel and assigning it to its DataContext. The ViewModel makes no references to the view. But with this lookup dialog the lines seem a little blurred to me. I envision the lookup having it's own ViewModel. When you lookup something, say an Item to be put in a Sales Order, we may want to get information like the Item's price from the lookup so that it can be copied in to the Sales Order record. So to do that the main ViewModel for the screen needs to know about the lookup's ViewModel. The View for the main screen needs to know about the View for the lookup too though because it has to be able to "attach" the lookup to a gui control so it can listen to key press events and know where to visually popup when it needs to be shown. I'm not sure if the code determining the visual position of the lookup should reside in the lookups ViewModel which would break the MVVM concept totally or maybe in the lookup's view's code behind which would muddy the purity of the view a bit since now the View isn't just the XAML.
The original lookup, after being created, would be given a reference to the control that it should attach to. It would then attach functions within its object to the key press and button click events (our edit boxes can have buttons built-in). When it was told to popup, it would figure out the current position of the control it is attached to so that it could figure out where to put itself. In the case of attaching it to a grid, it was actually attached to the column of the grid because there is only one instance of the lookup, and it would figure out the current position of the cell in the grid it is supposed to be popping up under.
What is the best way to do this while still staying in the realm of MVVM. I really would like to stay as "pure" as possible so I can come back later and add integration and possibly unit tests for the ViewModels in the program and these should be ViewModels that are "headless" (no View).
To make it easier to understand what I am trying to achieve I have included a picture of the screen I am recreating for my demo with the lookup shown.
I have problems with my current application which is developed in C# with WPF. The application consists of different flowcharts each contained in its own separate window.
At start-up all flowchart classes are instantiated and initialized in their window. Then the windows are made invisible and the flowchart menu appears.
With each new flowchart the application start up gets slower. The window initialization seems to consume a lot of time.
How could I approach this problem?
I thought of initialization when first needed or background initialization.
Note: I forgot a very important fact: The flowchart menu is created based on the other flowcharts, since every single flowchart is rendered as an image in order to display a thumbnail menu button. This is the problem which brough me to the performance impact anyway.
You have many approaches to this problem.
First, you have to remove the initialization from the c'tor.
Where to move it?
Either to Window_onLoad event, this way the app will first loaded and then start initializing the flow charts (using a new thread will avoid UI freeze).
Or once the user selects the required flow chart from the menu, you show the window and start initializing the inner flow chart, display a nice "loading.." animation while busy, and show the flow chart once you done.
I'd prefer the second approach, init each object when it's needed.
Edit:
Since you have to render the thumbs based on the flowcharts, i would do the following:
Move the flowcharts init to the main window Loaded event, and init each flowchart on a different thread, while busy display a nice "please wait.." animation. This way the main app window appears, the user see that the app is loading, your thumbs will be created simultaneously therefore loading time will be reduced. Once all the thumbs created, hide the animation.
Don't instantiate all the flowchart classes before you load the main window.
As a first approach I'd go with initialisation when needed.
If this proves to be unpopular as people don't like waiting then go for a background initialisation with the most popular or most recent flowchart instantiated first. This will be right most of the time so the user won't have to wait.
If you need to have a thumbnail of the flowchart then why not save the thumbnail from when the flowchart was last rendered and use that? So, when the flowchart is created first saved save a thumbnail at that point. Then when you populate the list pull that out of the database/off disk and render that.
Nobody's mentioned profiling yet, but why not just try (the last paragraph of) this?
You will easily see the dominant reason for the long time being taken.
Chances are, it's something fairly trivial that you can easily fix.
If you want more of an explanation, look here.
Can someone please help me work out how to open a Dialog Window,
the simplest scenario I can think of is:
We have a main window with a button and a Label,
when the user presses that button,
a dialog window with a text box and 2 buttons appear,
one button says submit,
when the user presses submit it closes the window,
it changes the color of the mainwindows background to red,
and takes the input placed in the textbox and changes a label on the main window to that content(I am bot so much worried about this part I get how to do this part),
while the other button just cancels the operation,
Assume that the Datacontext of the MainWindow and DialogWindow is MainWindowViewModel and UserInputViewModel respectivily.
Now on this link Cameron talks about using a service, ie IDialogService and DialogService
now could someone please explain to me how to implement those methods in the scenario above? Or if there is another way to do this then please let me know?
Please don't link me to any to any pages because I've probably read them all and I can't seem to get a clear understanding of what is meant to be happening?
~Slowly loosing his sanity because MVVM makes things so much harder :(
Not really an answer, but I think I'll add my POV anyway. How to use dialogs in an MVVM way, is something no one has really managed to do in an elegant fashion yet. There's basically 3 camps:
(1) The people who use an dialogservice like you described,
(2) The people who thinks that MVVM is good, but not something you should spent countless of hours trying to get right, so they use the codebehind, and
(3) people like me, who thinks that more often than not, the dialog and the parentview are so tied together that they should share viewmodels (as-in, the dialog is just one way of showing the data from your viewmodel).
The learning curve for MVVM can be slightly steeper when attempting to do something a little more advanced than simple data binding. Have you checked out the MVVM Light toolkit? It includes a Messenger class that facilitates sending messages around the place. A listener registers for messages they want, and a sender just publishes them. In this manner, neither the listener or sender know about each other, but can communicate. Meaning the View can register for a message, and the ViewModel can send one.
This question talks about doing something very similar to what you want to do. I recommend the MVVM Light toolkit by the way!
I'm not sure about how you use the results of a dialog to send them through to the ViewModel. I'm assuming the harder part for you is communicating from the VM to the View.
I am looking at doing a program as a hobby and to help a friend with a printing problem they have. The application is pretty simple, just taking in data and sending that data to a print job so my friend doesn't have to manage each thing individually.
My question is this: I want to use a tabbed main interface (Like how Meego OS is) The problem I have is this doesn't seem like it would be structured very well. That is, Instead of having a separate file for event handlers for each tab, they would all be in one file, the file with the tab control.
I thought about doing something like how some websites are made, [home.html, contact.html] [[the home icon in home.html is differentiated between contact.html when at home, contact icon is differentiated between home when on contact.html]] but I need to handle background tasks.
I know those tasks will be in a separate thread (well, at least that's what makes sense to me) but I am still not sure which is the standard method to do this.
Sorry for a wall of text, let me know what needs added or changed. Thanks :)
You can create a UserControl for each page and add them to the TabControl. The code for each page will be in each UserControl and thus a separate file.