Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I encountered a problem.
i'm working with some outer control at my xaml, and i need to call to his functions from
my view model.
i created a property from his type at my view model and i want to bind them.
how can i bind an object?

Example: i have a Text Block at xaml and i want in code to call to his focus()

how can i do it?

Thanks, Ofer.
Posted
Comments
Sergey Alexandrovich Kryukov 15-Jan-14 10:31am    
Too vague to discuss anything seriously. And what is "to call to focus"? there is no such thing.
I guess you need to learn WPF binding, which is a whole big topic, as well as many other things which won't be a matter of a Quick Answer. If you have more specific questions, we will gladly help you.
—SA
imbaro 15-Jan-14 11:09am    
its a spesific subject.
I want to bind an element.
Usually binding os for properties, like textblock text, binsing to string property.
I want to bind the textblock to a textblock property, so i can use it.
Is it understandable now?
Sergey Alexandrovich Kryukov 15-Jan-14 11:15am    
Not clear. You need to describe what did you want to achieve, what's expected behavior, what is observed behavior, why do you feel it's wrong. If you have some exceptions, describe steps to reproduce, complete exception information. Comment the points in code related to exception throwing/propagation. Post all what's relevant. See also: http://www.sscce.org.

—SA

1 solution

You can't do what you are trying easily - setting the focus to a particular control is a pain in MVVM generally.

It also goes against what MVVM is all about - the VM shouldn't really know focus is going to be set at all.

If you do need to do it, you can use attached properties - see here[^]

But, depending on your application, it may be simpler to set the focus in code behind on some event or other.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900