I have the same porblem every time. I want to create a custom control with "UIElement" DependencyProperty. So, on which element in XAML I could create binding to this DependencyProperty?
Canvas's Children property says that it's impossible, Grid even don't have "Children" property in XAML and so on.
Thank you!
Not sure if this is what you are looking for but javascript knockout works well with UI bindings:
http://knockoutjs.com/
Also take a look at handlebars:
http://handlebarsjs.com/
Hope that helps
Related
Is there a possibility to prevent a Expander control in WPF to collapse, when certain conditions are given. For my usecase it is not possible to do it directly in the xaml, because whether the Expander can be collapsed or not depends on condition just known during run time.
Its no option for me to use an event, because the project is a test project to seperate gui and code strictly.
Perhaps you can bind to the IsExpanded property.
For example you can use a DataTrigger, MultiDataTrigger, ValueConverter, or MultiValueConverter to manage the data binding to the IsExpanded property.
There's also a interesting article here that may help you.
If you want to set the Expander to always remain toggle-on. Just leaving it here.
<Expander IsExpanded="True"></Expander>
I'm relatively new to C# and the idea of data binding (that is, I'm not sure I completely understand it). I am looking to try to bind NavigationPage's BarBackgroundColorProperty for sake of being able to change my root page's bar background color multiple times for a theme feature I'm trying to implement. I've searched around for examples of binding this property and haven't had much luck. Could someone point me in the right direction? If anything is unclear, please let me know. Thanks guys!
Assuming you have an instance of NavigationPage called myBindingPage and a view model that extends INotifyPropertyChanged called myViewModel that has a property called BarBgColor, you should be able to set up a binding like this:
myBindingPage.SetBinding(NavigationPage.BarBackgroundColorProperty, new Binding("BarBgColor"));
N.B. I haven't actually tried this, but the API doc does list BarBackgroundColor as a bindable property.
How can I change properties of some controls in DataTemplate that placed in resource from code?
I use .NET 3.5, so DataTemplate doesn't have Template property.
Take a look at DataTemplateSelectors
--Edit--
I'm sorry I did not understand the question at first, I think the best way would be to write an extra template, that looks the way you want to modify the other one, find it and assign it
to the list control.
Here is a little example
I'm trying to create a binding from my custom control to objects that are in a BindingList.
While with textbox, I can easily write
textBox.DataBindings.Add("Text",myBindingList,"PropertyOfObjectOfBindingList")
With my custom property "Value", this thing doesn't work (the object doesn't get updated).
What should I implement with my custom control to make it works? I already implemented INotifyPropertyChanged, but it doesn't work.
I just want make this line works:
customControl.DataBindings.Add("CustomProperty",myBindingList,"PropertyOfObjectOfBindingList")
EDIT 1:
I read this around web: http://kbalertz.com/327413/control-using-Visual.aspx however is not working for me at the moment, maybe I'm doing something wrong
Since you said your bound object doesn't get updated (I assume from Control -> Object changes), but it is bound correctly, maybe this will help:
customControl.DataBindings.Add("CustomProperty", list, "BoundObjectProperty",
false, DataSourceUpdateMode.OnPropertyChanged);
Maybe the Implementing complex data binding in custom controls article will help.
I solved the problem by myself:
While the article I linked is a good suggestion, there is a wrong part; you don't have to create an event in your custom class with PropertyChangedEventHandler, but just with EventHandler.
public event EventHandler CustomPropertyChanged;
Is enough to make everything works. Obviusly you have to call it when your property changes
EDIT 1:
I discovered a bad thing, while on textboxes, if the control lose focus the bindinglist get updated, on my custom controls this thing happens only when I change selected item in listbox.
I don't find a way to solve this at the moment.
In a DataTemplate I want to show the Control which is actually replaced by the DataTemplate. With error validation, this is possible by using <AdornedElementPlaceHolder />. However, this seems not to work in a normal DataTemplate.
I think there would be a simple solution, but just can't find it.
Thanks a lot
This is not possible and here is why. DataTemplate doesn't replace anything. Instead, a control that defines a DataTemplate contains the content provided by it. If it was possible then there would be an infinite loop (control -> data template -> control -> data template -> ...).
I suggest you read the following article to fully understand data templates: http://msdn.microsoft.com/en-us/library/ms742521.aspx
A DataTemplate in some sense "replaces" a data object and not a UI object - in other words, not a Control. If you are trying to work with properties of the Control (usually either a ContentControl or ItemsControl) that is using the template, try a RelativeSource Binding where the AncestorType is the type of the Control.