|
This is in real mess. Why don't you use a Converter and do these operations there.
|
|
|
|
|
Is it acceptable from a MVVM standpoint to put form related (data independent) code in the code-behind file of the view?
Example:
private void RightButtonClick(object sender, RoutedEventArgs e)
{
ListBoxPreview.SelectedIndex = ListBoxPreview.SelectedIndex + 1;
}
It is an agnostic function so I think it is alright but I am curious from a clinical standpoint what you guys think.
Cheers, --EA
|
|
|
|
|
One of the funny things about MVVM is that people seem to get it into their heads that MVVM means no code behind the view, and that's just silly. If you want to put something in the view because it's view related, then go for it. Only the anal would criticise you.
|
|
|
|
|
Ha, the internet is where the anal come to practice their craft I think.
Regardless, thank you for the insight. I read someone say that you could remove the code behind from a view and still have it work fine. I am sure that was purely contextual though.
By the by, should the MoXAML power toys work with VS 2010 or just 2008?
Cheers, --EA
|
|
|
|
|
At the moment, it's just 2008 - when I've finished the article I'm working on, I'll be upgrading it to 2010.
|
|
|
|
|
I am in the same boat as you, just getting started with SL. Having read a swag of articles, studied a number of frameworks and discussed it to death we are now getting into some development. I agree with Pete, only the anal will argue that there should be no code behind. I find we end up with quite a lot sitting in code.
When the renderer in VS10 won't render the view because it can't deal with the viewmodellocator I have no compunction doing the binding in code therefore making the IDE behave.
There seems to be lots of stuff that is purely View related that still need to be done in the code.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
So long as you dont attempt to access a model attribute, this code looks fine.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
I'm still struggling with these bloody things and I think it is a design issue.
I have a standard MVVM UI with view and viewmodels. I have a viemodellocator that has a static instance of the viewmodels. Each viewmodel basically represents a table in the database.
Two of the viewmodels I have are Trade and Currency, each Trade requires a currency so the view (Trade) needs to get a list of currencies to bind to the combobox.
I service the view with the static Trade VM from the viewmodellocator. TradeVM has a CurrencyList collection that is set to the CurrencyList in the static viewmodellocator. This works fine, ONCE. Then changing the selected Trade record in the Trade VM disturbs the binding and the combobox no longer binds.
This seems to be a widespread issue and there are various work arounds which are plain ugly. Does anyone have a recommendation, blog, article that demonstrates a simple and elegant solution to this rather nasty problem. Or am I doing this completely wrong and need to redesign my approach.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Could you post the project (even in a pared down form) somewhere like dropbox, and I'll download it and have a look at it? I'm having trouble visualising how you've laid out the solution and what the interaction is, so I can't really offer relevant advice.
|
|
|
|
|
I'll see what I can put together tomorrow, I tried to email you a while ago, had to use your linkedin connection as you don't encourage it here. I think the wife has a dropbox so I'll see what I can do, thanks.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have a gmail account - you can contact me on that.
|
|
|
|
|
I have just loaded up your inbox.
It seems the problem is if you create a binding and then refresh either of the underlying datasources List<> the binding is broken. Trying to work around this has got me stumped.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Pete O'Hanlon wrote: I'm having trouble visualising how you've laid out the solution
I'm not surprised, I'm going cross eyed trying to keep track of all the bits needed to make this thing work.
I just spent the last 2 hours putting together an app that demonstrated the problem and bugger me, I can't repeat the problem in the demo app, bloody thing works perfectly.
Now to chuck the code in the dev app and start again!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It turns out this is a well known problem it is just that I am coming into SL late.
When changing the underlying datasource the intemsource and the selecteditem are reset. After chasing around for some time I settled on this solution [^] This means each combo will need to be manually bound in the code behind.
Except it needs a bit more!
In my viewmodel I have a SetSelected(int iID) method that will set the current selected item in a List<> based in the id. This is then used to set the combobox selected item.
Calling the BindCombo when the visibility changes seems to be the best event to use
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello RAH
So I have your Problem.
if you solved your problem please send your answer to mmbarzanooni@gmail.com.
Thanks a lot.
Mohammad Barzanooni
|
|
|
|
|
Read the prior post it links to the solution I used.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I dont find any way to do it
Someone can help me here ?
|
|
|
|
|
Canvas.SetZIndex(yourControl, newValue);
It's there... Just moved.
|
|
|
|
|
That exactly what i did - but its not work.
|
|
|
|
|
What exactly are you trying to do? You can't move a control behind its parent, if that's what you're trying. You can only shuffle the order of controls in the same container.
Positive/higher values move it to the front, negative/lower values move it to the back. The default for all controls is zero.
|
|
|
|
|
The solution given by Ian is the perfect one.
However, as an alternative you could try the "old solution" of hiding / showing controls as per your requirements.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
I know that this is how i need to do it - but i don't know why its not working
Yes, I change the parent visibility - and i don't know how to recover from this situation .. ( or how to shuffle the order of controls back )
|
|
|
|
|
Yanshof wrote: Yes, I change the parent visibility - and i don't know how to recover from this situation .. ( or how to shuffle the order of controls back )
Hide one and show the other - and then hide the other show the first one.
This should work, unless these controls are contained one inside the other.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
This is not working also.
The winform usercontrol is stay on the top of all the other WPF controls.
I try to show/hide this control, change his z-order, and nothing happened.
If i call 'hide' to this control => its really hide it - but this control need to be on z-order specific - so i must find any other solution.
This can be Microsoft bug ?
|
|
|
|
|
Weird. You might want to paste some of your code here so that someone can help you.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|