I work with a lot of page. I calculate some variable other pages and i want write the result other page. How can i make this?
I tried make static textbox but it did not work.
I can make the static variables but i want to static textbox. I want to access to textbox for every page.
A possible solution is to use a utility like MVVM light that implements a messenger service. Every page that needs to change to the textbox can send a message with the new contents and the page with the textbox can subscribe to those messages.
It seems like you're coupling data and pages much too tightly. In general your views and your data should be completely separated. If you do your data calculations in totally separate classes it is usually easier to get that data wherever you need it. If you're not using the MVVM pattern you should consider it.
Related
I'm working with the Bot Framework and I want to display list of choices which have image attached by using method PromptDialog.Choice in order to take advantage of the ResumeAfterChoose method to control my business logic. However, I've only seen the Attachment Dialog which has written in EchoBot Sample and it only creates list of messages that make me difficult to handle my business logic after client choose one of the list. Please show me the way to implement that. Thanks
Out of the box, you can't do that. There are a few ways to achieve that though.
First of all, you are saying that using attachments won't work for you because you won't be able to handle your business logic. That's partially true; but not for the reason you are mentioning.
You could put together a list of HeroCards with buttons and use the carousel layout for the attachments (see the RichCards and the CarouselCards samples). Then, you can just perform a context.Wait to a different method (similar to the ResumeAfterChoose method in the PromptDialog) and handle the logic there. That method will get the value of the button clicked and then you can perform your business logic. Now... the caveat with that is that if the user writes anything not aligned to the options you still will hit this method.
Guess what? What I just described is extremely similar to what the PromptDialog.Choice does behind the scenes... with the only difference that it adds a Retry logic to handle the caveat I mentioned and that the layout used is a list one because it just render a single HeroCard with multiple buttons (the options)
The way I would go in this case, is trying to put together a custom PromptStyler, override the Apply<T> method and add your logic to render the Choice options in the way you want based on the PromptStyle used.
By default the PromptDialog.Choice uses PromptStyle.Auto, that at the end of the game (in the PromptStyler) converts the options into a HeroCard with multiple buttons. You could easily change that logic to create multiple cards and also uses images for them.
I have a list of custom controls that should look something like this
Before I start to implement them through a custom or user control in WPF (via MVVM), I want to ask if I do everything right. I create a DataTemplate and binding properties I need (these are the numeric values (0.13) in columns) and ItemTemplat'ing it to listview or listbox. Also I'm having an observable collection of viewmodels for these templates and every viewmodel sends some specific numeric data through short intervals from slave device. Also I need this green element to be clicked (just to add a button to a template I guess) and having displayed an additonal window with real time plots. So my question is: Is this the right approach I'm talking about or do I have something wrong? I'm quite new to WPF, so please excuse me. I dont think that it is a great challenge to implement something like this.
I'm rather new to this model as well, however one thing I have found that has helped me with managing multiple View Models has been an IOC Locator. An example can be found here:
http://dotnetpattern.com/mvvm-light-toolkit-example
I am creating a new winforms application that will have datagridviews which will load matrix data, and I want the user to be able to do a bunch of operations on the data, like showing/hiding columns, editing cell values, and filtering too.
I thought of using the MVP pattern (Model, View, Presenter).
I wanted to create a presenter class, which would handle all the logic (meaning any events that the user triggers), eventually end up in the presenter which will work on the raw data (the matrices). This seems logical up to now but my question is what do I do if I want to pass the controls themselves (like the datagridviews)? Should these controls be sent the presenter class or is that bad design?
Perhaps it's better to find ways to only modify the raw data and then update my datagridviews?
It is not a good idea to pass around controls. If you're going to use a pattern such as "MVP", then you should have the "model" contain the representation of the "view". In this case if there are various details pertaining to a set of data it belongs in the model. Then you pass the model around.
Perhaps it's better to find ways to only modify the raw data and then update my datagridviews?
So, to answer this question, "yes". Use the model to wrap the data and pass it around.
Update
Specifically, with WinForms controls belong to containers, being that they are reference types and have lots of exposed events you run a HUGE risk of passing a reference from one Form to another Form. Now, imagine that the first Form is done being used and closes and disposes, it kills the reference to the control and attempts to unwire events. Do you see where I'm going with this? It quickly becomes a nightmare trying to correctly cleanup references, and un wire event handler and since controls belong to one container by design it breaks that paradigm.
It's better to have a separation of concerns. If you need a view to have certain data, it's always best to pass around the data itself...
This may be a really basic question to experienced programmers but I started on VB6, and now I'm trying to accomplish same stuff on C# which is object oriented.
Suppose I have a class with a method to add two numbers on textboxes and I run that in the click handler of a button (Doesn't matter if it is static or not), then I have the result and I display it on the screen (maybe in another textbox), the user click another button, how do I recover the result on the other button handler?, what's the best practice?, I know I can read the result on the textbox, but if the result was displayed on a Messagebox.Show or in console?.
What's the best practice to save results instead of using helper textboxes or global variables?
On VB6 I use invisible textboxes, so my forms looks really messy, but thats the way to there.
Using C# + XAML + WPF
Usually that is what a model is for. It is the data-state of what is shown (and more, as some information may not be displayed at all times or just used as utility). The view often has a reference to the model which you then can access in the handlers and manipulate.
I'd suggest reading up on design patterns like Model-View-Controller and for WPF specifially Model-View-ViewModel.
Also, WPF has a few powerful mechanics like data binding, which makes synchronizing your data with the view a lot easier, do not treat your view as a model.
I'm trying to make something like a quiz application where 3 questions will be brought up on screen at a time, allowing the user the check a radio button containing "Yes" or "No", and have an answer come up appropriately to his response. The questions will continually come from a database I'm using.
After a few attempts I've figured that using x:Name property is not a great solution, since it doesn't allow me to use a loop in order to change the questions and answers. Is there any other way to make a grid with the same types of objects in each cell, being able to access each object inside each cell of the grid in the code-behind?
Here is list of steps you need to implement,
Need to create QuestionModel, contains question properties, make sure your model inherits INotifyPropertyChanged.
Need to create ViewModel, which contains data objects, public/dependency properties
Need to bind/set data objects/properties on viewmodel constructor
Need to set your ViewModel as a DataContext of your View(.xaml) (You can create this on zammel directly and codebehind as well
Need to bind your UI objects like Question/answers/yes-no with viewmodel properties accordingly
WPF/Silverlight has their own fundamentals like Data Binding, Resources, Compiler, Dependency Properties. Above steps comprises MVVM design pattern. During each steps, please google for specific stuff.