I have a control whose binding is set as OneWay.
How can I force the value to be re-evaluated in code?
Get the binding expression and call UpdateTarget:
BindingExpression binding = Control.GetBindingExpression(TextBox.TextProperty)
binding.UpdateTarget()
Of course, if you implement the INotifyPropertyChanged interface on the class that holds the source property for your binding then WPF will handle the updating for you automatically.
Related
Where is it gone ?
let triggerFindNext,findNextEvent = IEvent.create<EventArgs>()
The field, constructor or member 'create' is not defined
maybe I must to add some Framework for it ?
The IEvent.create function has been deprecated. A new way of creating events is to create instance of the Event type. In the simplest case you can write just this:
let evt = new Event<EventArgs>()
// Trigger event (instead of first element of the tuple)
evt.Trigger()
// Returns IEvent<EventArgs> value (instead of second element of the tuple)
evt.Publish
This represents event using IEvent<_> value (and doesn't generate .NET compatible event if you expose it as a property) and it uses generic Handler<_> delegate from F# libraries.
(If you want to generate .NET compatible event usable from C# then you need to add CLIEvent attribute and you can use variant of Event that takes delegate as generic parameter as described in the answer already mentioned by others)
EDIT: I posted a more complete F# snippet (with nicer formatting) here: http://fssnip.net/1d
I have an asp.net mvc view, which is using Telerik's grid.
Html.Telerik.Grid(Model.Items)
Model.Items is IQueryable, but the Grid requires me to cast it:
For example:
Html.Telerik.Grid((IQueryable<Product>)Model.Items)
The problem is: I don't know what type is in Model.Items (it can be IQueryable<Product>, IQueryable<Book> and many others).
What I also have is Model.ItemsType, which can have following values: typeof(IQueryable<Product>), typeof(IQueryable<Book>)...
How can I cast the IQueryable to IQueryable<T>, when I don't know the type of T in advance?
Generic types need to be known at compile-time, not determined at run-time.
What is the type of Model.Items? If it's derived from IEnumerable<T> then assuming you have a reference to System.Linq then you should be able to call the AsQueryable() extension method.
You're going to need to use reflection to invoke the Grid method when you don't know the T ahead of time, because there's no way to do it at compile time. If Model.Items actually is an IQueryable, then you don't need to cast it; just pass it along as the parameter during the reflection-based invocation (which takes all parameters as type object anyway).
Perhaps you can try binding to IEnumerable. Check the 'Binding to a collection of dynamic objects with MVC3 Razor' code library entry.
[Bindable]
/**
* Display output of video device.
*/
public var videoLocal : Video;
Anyone knows?
[Bindable] is a one of several meta tags that you can use in flex ActionScript code. It can be applied to properties, or methods that are marked in any scope. It cannot be used with static class members.
The key to using the [Bindable] meta tag is understanding what is going on under the hood when you use it. Essentially using data binding is a type of shorthand for adding event listeners and dispatching events.
There are two basic forms of the [Bindable] tag. The first is just [Bindable] followed by a var/property declaration. The Second is [Bindable(event="eventname")] followed by either a var/property declaration, a function/method declaration or one half of a getter/setter declaration.
I'll explain the longer notation first since the other builds on the same concept but with even more shorthand.
When you use [Bindable(event="eventname")] you are essentially telling the compiler that this var/property/function/method (call this the instance member) is 'available' to be used as the source for data binding. You are also telling it that when the value of the instance member has been invalidated/changed and it needs to be re-read that the "eventname" event will be dispatched.
In this longer form this all you are doing. You the developer are responsible for actually dispatching the "eventname" event whenever the value needs to be updated in the binding subscribers.
The real efficiency of using data binding comes on the subscribing side. The typical notation you will see in MXML is value="{instance.propertyName}" When you use the notation { } you are telling the compiler to do the following:
Create an event listener that listens to the event named in the bindable meta tag
In that event listener re-read the instance.propertyName and update this value
If you use the shorter form [Bindable], and you add the tag before a property/var, the compiler fills in the blanks and adds some additional functionality to make the property bindable. Essentially you are telling the compiler "add the events and methods you need to make this property bindable"
Now the way to think of what the compiler will do under the hood is this.
make a private version of your var
create an "event" to trigger the binding
create a getter function with scope and name of your original var that returns the private verson of the var when called.
create a setter function with scope and name of your original var that sets the private version of the var when called AND dispatches the triggering event.
In essence the compiler will do much of the work for you.
[Bindable]
public var xyz
is equivalent to
private var _xyz:String;
[Bindable(event="updateXYZValue")]
public function get xyz():String{
return _xyz;
}
public function set xyz(newxyz:String):void{
_xyz = newxyz;
dispatchEvent(new Event("updateXYZValue"));
}
The only functional differences in these is that in the first instance;
you do not know the name of the event that will be dispatched to trigger the binding
there is no way to update the underlying value without triggering the data binding
This second example also demonstrates one special case of the [Bindable] meta tag. This is that when you are applying it to a getter/setter pair defined for the same variable name you need only apply it to one or the other, it will apply to both. Typically you should set it on the getter.
You can use either notation on a function/method however if you do not specify an event the binding will never be triggered so if you are trying to bind to a function you should alway specify an event. It is also possible to specify more than one triggering event by stacking the tag. eg.
[Bindable(event="metaDataChanged")]
[Bindable(event="metaObjectUpdated")]
public function readMyMetaData():MetaDataObject{
var myMetaDataObject:MetaDataObject;
.
.
.
return myMetaDataObject;
}
This would presume that somewhere else you your class you will dispatch this metaDataChanged event or the metaObjectUpdated event when you want trigger the binding.
Also note that with this notation you can tie the binding of any instance member to any event that the instance will dispatch. Even inherited events that you yourself do not generate such as FrameEnter, OnChange, etc...
Data bindings can also be setup and destroyed during runtime. If you are interested in this take a look at the mx.binding.utils classes.
It is used in Databinding with Flex, you can read more about it here
http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_2.html
Creating properties to use as the source for data binding
When you create a property that you
want to use as the source of a data
binding expression, Flex can
automatically copy the value of the
source property to any destination
property when the source property
changes. To signal to Flex to perform
the copy, you must use the [Bindable]
data tag to register the property with
Flex.
As an addition to what Justin said, you can actually use two ways data binding in Flex with the # character. Here's an example:
<s:TextInput id="txt1" text="#{txt2.text}" />
For a working example with source code enabled you can check out this article I wrote a while back:
Two-ways data binding in Flex
I'm not sure if this is a bug, or a feature. I have an action param that takes a ListRequest object with a few string properties. .NET MVC dutifully maps the query string params of the same name to the ListRequest objects' properties.
I add a ListRequest.Filters property, which is to be a list of strings taken from the querystring: ?filter=foo&filter=bar
If I declare .Filters as a Get/Set of type List(Of String), DefaultModelBinder does exactly what you would expect. However, if I declare .Filters as a Get/Set of IList(Of String) instead, DefaultModelBinder stops binding values to that property completely.
Is this a feature, or a bug?
Sounds like a feature to me. The model binder needs concrete types to bind to.
If you tell it to bind to an interface it can't do anything because it can't instantiate an interface to bind to.
EDIT: Interesting
Judging by the source code, it seems that it will bind to a model that is a generic type of IEnumerable, ICollection, IList or IDictionary BUT it won't bind on a model's property that is of a generic type.
So I wouldn't say it's a bug... I'd just say that it's a feature that they have overlooked. :-)
I don't really see the need for element to element binding in Silverlight 3 if using MVVM. Won't having one property directly affect another proper cause that property to be untestable?
To me, it makes more sense to do a two way binding to a explicit property defined in the ViewModel.
I agree that the use of MVVM severely deflates the usefulness of element to element binding.
Still, if all you are doing is binding two elements using a ViewModel property... what can you test? You can test that setting a property in the ViewModel sends a PropertyChanged event... but thats about it. Only when something else cares about that value is it useful to test a property like that.
In the simple cases, I can see element2element binding being more efficient and less code.