Assuming we have such control:
public partial class MyUserControl : UserControl { public MyUserControl() { InitializeComponent(); } public string Foo { get; set; } }
How can I set ‘Foo’ property value declaratively in MyUserControl.xaml?
<UserControl x:Class='Test.MyUserControl' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <!-- Looking for some thing like this --> <Foo>Hola</Foo> </UserControl>
To be more clear: How can I set in XAML a value for the property defined in code-behind.
This can only be achieved in xaml by inheritance:
You are providing an implementation for your control. So the only way to achieve a value in xaml for your control is through inheritance.
Your second UserControl will look like this:
or: