Is it possible to change property value from xaml?
Imagine we have a usercontrol which have a property that is initialized already
public class MyUserControl : UserControl
{
...
public SomeClass MainWindow
{
get
{
return _someClass ?? (_someClass = new SomeClass();)
}
}
}
Now is it possible to change property of SomeClass without initializing it from xaml, and without animation?
Why xaml doesn’t allow syntax to write <UserControl.MainWindow.Property>?
Add a setter to the property and allow the XAML to create its own SomeClass according to its need – that’s now it is usually done.
XAML is declarative language, it doesn’t try to be Turing complete or something like that, it merely describes creation of objects.
Of course, there is one extreme solution. But please, don’t do it. For your sake, and everyone else’s 🙂
EDIT:
Another solution could be to create a new property in the UserControl, and synchronize this property with property of SomeClass (
set{ this._someClass.someProperty = value; }). If you set this property in XAML declaration of the UserControl, the change will be propagated to the _someClass member.Of course the wrapper property will have to be a dependency property, if you want to bind to the wrapped property.