|
I have heard it said WPF was designed with MVVM in mind.
Anyone know if this is true? Any documentation to support this?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
That's not quite right. MVVM was invented by John Gossman to support WPF development, because WPF provided far superior binding capabilities to its predecessors. It's often said that WPF was designed with MVVM in mind, but that is not the case - in fact, John had been working on Avalon for three years before he publicly coined the term Model View ViewModel[^].
|
|
|
|
|
Although, the answer does very much depend on what you understand MVVM to mean. The underlying 'essence' of the pattern is rooted in the Presentation Model pattern which Martin Fowler described before the WPF framework was developed.
http://martinfowler.com/eaaDev/PresentationModel.html[^]
This is something that Gossman openly acknowledges. In my opinion, MVVM is a WPF / Silverlight specific implementation of the Presentation Model, in that the general understanding is that you set your view-model as the DataContext of the view, minimise code-behind and promote design-time data and unit testing. WPF was designed with these concepts very much in mind.
|
|
|
|
|
Ahh, time for the Disciples to go forth bringing knowledge to the masses.
Indeed, MVVM derives from the Model View Presenter, but it is closely tied to Model View Passive Presenter which Fowler came up with at roughly the same time as John. It was a logical extension of MVP, so there's no real suspicion about the relatively simultaneous independent creation of logically related concepts.
|
|
|
|
|
Indeed. What Pete said! It's all MV-Poo
However, I do get very annoyed when people take the conceptually simple and elegant MVVM pattern and extend it into something that is much harder to comprehend. Does anyone really need the Model-View-Presenter-ViewModel (MVPVM) pattern?
http://msdn.microsoft.com/en-us/magazine/hh580734.aspx[^]
Admittedly, I haven;t read the article - so maybe I am a bit hasty in judging. However, what I really like about MVVM is that I can explain it to any competent developer within about 5 mins and know that they will follow it correctly. The same cannot be said for 'classic' MVC pattern.
|
|
|
|
|
Indeed, you're right. MVVM is a simple concept - granted there are subtleties, but these are implementation subtleties and nothing to do with the underlying pattern. What annoys me is when people heap all sorts of different patterns on top and then say, "this is MVVM".
For instance, although we all use Mediators or Messengers, they are nothing to do with MVVM - they are merely a way to help communicate between separated concerns. Similarly, when people say that MVVM is DI or IoC, again, these are just other techniques to help - they aren't MVVM. Properly applied, they help make better code, but they are not part of the core MVVM concept.
Possibly my biggest bugbear is when people think that MVVM means that you have to remove ALL code behind. That's just plain errant nonsense. If you want to trigger an animation just because your window is closing then, by all means, trigger it from code behind.
Ah well, we're just rehashing old ground here.
|
|
|
|
|
|
I don't like it. Messages are getting lost this way.
|
|
|
|
|
Pete O'Hanlon wrote: Possibly my biggest bugbear is when people think that MVVM means that you have
to remove ALL code behind. That's just plain errant nonsense. If you want to
trigger an animation just because your window is closing then, by all means,
trigger it from code behind.
I know this was just an example, but this is definitely something that can be done entirely in XAML. I'm one of those guys that self enforce the no code-behind rule . So far, I haven't found a need to have code behind. There are plenty of MVVM tricks to get around the need... if you are writing a lot of code behind, you should probably repackage it in a nice MVVM friendly UserControl or something of that sort.
If you start allowing code behind, it gets hard to draw the line... you end up with a lot of "I was feeling lazy that day, so I'm going to throw it in the code behind and move it later" -- which never happens.
Plus, you end up with your logic split across two .cs files 
|
|
|
|
|
You're right, there are lots of MVVM tricks that can be used to remove all the code behind. But at what point does it become too much? Each additional thing you put in place becomes yet something between you wanting to do something and actually doing it, and each bit takes that bit extra time. I am all in favour of removing unnecessary code behind, but when it becomes dogmatic then you have gone too far.
|
|
|
|
|
No this is not true (as per wiki[^]).
"MVVM was designed to make use of specific functions in WPF to better facilitate the separation of View layer development from the rest of the pattern by removing virtually all “code-behind” from the View layer."
|
|
|
|
|
A few years ago, I wrote a native WPF task dialog. It has served me wonderfully for years. It looks exactly like the standard Windows task dialog, but allows me to re-template certain areas. I've never actually had to use the custom re-templating until now, so I never really thought about this issue...
Cliffs:
* the task dialog is essentially a UserControl
* it's written all "WPF-y"... to re-template the content section, I would do:
td.ContentTemplate = (DataTemplate)Application.Current.FindResource("InputPromptTemplate");
for example.
That part all works fine. The custom template works as intended. The question is, I never really thought of a way to allow data binding in that template. The data context is going to be set to the task dialog's data context obviously, not my VM. So If I was to do something like:
<CheckBox IsChecked="{Binding MyCustomCheckBox}" />
It would obviously expect MyCustomCheckBox to be a part of the TaskDialog class and it isn't. The TaskDialog is a pop up dialog, so I can't chase up the VisualTree from XAML either.
Any ideas how to set this up? It isn't really MVVM actually, just using the TaskDialog straight up in this manner would have the same issue.
|
|
|
|
|
Hi guys,
I have to create a control similar with the one from browsers -> on editing a listbox appear with the history.
The problem is I don't know exactly how to "anchor", the listbox control under the text box cotrol; or what to use.
I have a groupbox with a grid, inside my textbox. I create dynamicaly the ListBox inside the parrent element but I don't know how to display it under the textbox.
george
|
|
|
|
|
Use a StackPanel control and place the textbox above the ListBox.
For example,
<StackPanel>
<TextBox/>
<ListBox>
<DataTemplate/>
</ListBox>
</StackPanel>
|
|
|
|
|
I did not tried but there are 2 problems.
1. I guess if I used like this ...the listbox will be drawed inside my groupbox and grid.
I want to be displayed just under the textbox and drawed, over , outside the groupbox, grid.
Is it possible?
2. What if I want to have something like the autocompletion menu from Visual Studio 2010 and want to display a listbox at a specific position inside the control.
|
|
|
|
|
Though I'm not able to visualize the exact UI you require, with Silverlight, you should be able to do this via templating and styling.
|
|
|
|
|
The control in the browser where you enter a URL? Thats a ComboBox, not a TextBox with an anchored ListBox. Just set the style on the ComboBox so that it is editable.
|
|
|
|
|
ha...
yes, I will use a combobox.
It would have been interesting to build my own combobox.
|
|
|
|
|
I've changed my mind and now I need a DataGrid displayed as a popup by the ComboBox.
I would like to do this only with xaml. I try to put the datagrid inside the ContentPresenter but it is not possible.
Any ideea how to do this?
Is it a good Ideea to have something like this:
inside
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
to put a StackPanel with a text box and a DataGrid by default hidden.
Only when I put text inside textbox to activate it?
like:
<Style TargetType="ComboBox" x:Key="newTemplate">
<!--Set the Background, Foreground, FontSize, Width,
Height, Margin, and Template properties for
the Button.-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<StackPanel>
<TextBox>
Here is the text box, to be added a button down
</TextBox>
<DataGrid
<DataGrid.Columns>
</DataGrid>
</StackPanel>
modified 12-Mar-12 11:31am.
|
|
|
|
|
Hi,
I have a silverlight 3 application, which calls Workflow service to send mails to students (say 10 students).
Calling the workflow service to send mail to 10 students works fine for the first time. And this fails when I hit the service for the second time.
The exception which I get is the "CommunicationException() was unhandled by user code: The remote server returned an error: NotFound."
The exception occurs in the generated Reference.cs file :
public bool EndMailingDetails(System.IAsyncResult result)
{
object[] _args = new object[0];
bool _result = ((bool)(base.EndInvoke
("MailingDetails", _args, result)));
return _result;
}
I have doubt that the workflow instance which got intiated when I called the workflow service for the first time still exists which blocks me from calling the the same workflow service for the second time.
However I am not able to figure out where this workflow instanace gets created and how to destroy the already existing instance, to call the service without exceptions for the next time.
Any help would be of great help.
Thanks
|
|
|
|
|
Hi there, in my app, I want to allow user to change the style of the individual WPF element, say Button, Label etc and when it is changed, the app should show the modified style for that element. Additionally, I want to load these modifiable elements as the user chooses to modify.
For eg. consider there is a listbox listing all the style modifiable UI elements.
When user selects MyStyleButton, the app should show the button with last customized style. Then the user should be able to customize the look and feel say color using the color picker.
When the user opens the app next time, he should see the changes color.
The same can be though of if the user selects say MyStyleLabel from listbox, and changes the porperty say Font. So how should I load the desired Label, how should I store the changed style values?
Also how can I load those customization UI, like ColorPicker given say I have stored "Color" in the Tag property of the button and "Font" for label.
Please help. I have started learning WPF. So I am not a Pro in WPF, but good at C#.NET, ASP.NET and ADO.NET. I didnt got reply on msdn. I am in hurry. So pleaseeeeeeee help. Thank you.
|
|
|
|
|
|
Mahesha999 wrote: I didnt got reply on msdn.
I'm not surprised you did not get a response, do you actually have a business case for this interface or is it something you have thought up? To me it sounds like a nightmare, but then I'm a LOB developer.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mahesha999 wrote: Please help. I have started learning WPF. So I am not a Pro in WPF, but good at
C#.NET, ASP.NET and ADO.NET. I didnt got reply on msdn. I am in hurry. So
pleaseeeeeeee help.
Unfortunately, what you are trying to achieve is actually quite complex, requiring quite a bit of plumbing work; including storing and retrieving these values, managing binding to the items, and much, much more. You may be in a hurry, but I doubt anyone is going to have the time to help you come up with a complete solution here.
|
|
|
|
|
Thanks alot for atleast commenting. Actually late but finally I got some response on MSDN here: http://social.msdn.microsoft.com/Forums/en/wpf/thread/abc3c8e2-2105-4d2e-9276-de6ff9c22475?prof=required[^]
Now what I have thought, I will create a custom styled WPF buttons, and store its properties in separate XML, when user selects any of them, I will retrieve the properties from XML and when user changes the properties I will change Xml. Rough idea. And yes I will be using list to store mapping between control name and Xml element.
Any thoughts? Anything that can help solve any of the part of my effort. Like in that MSDN thread, I got clue to use Xml Data Source. Actually nice suggestion. What you think. Should I use XML data source or XML API like XmlReader?
Thank you for your reply. You guys are seriously caring. 
|
|
|
|