I don't konow how to set Path inside UserControl based on Parameter:
User control:
<UserControl x:Class="WpfApplication3.TestControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase">
<Grid>
<TextBox Text="{Binding Path=MyPath}"/>
</Grid>
</UserControl>
Code behind:
public partial class TestControl : UserControl
{
public string MyPath
{
get { return (string)GetValue(MyPathProperty); }
set { SetValue(MyPathProperty, value); }
}
public static readonly DependencyProperty MyPathProperty =
DependencyProperty.Register("MyPath", typeof(string), typeof(TestControl), new UIPropertyMetadata(""));
}
And how I plan to use it:
<local:TestControl MyPath="FirstName"></local:TestControl>
DataContext will be obtain from parent object, and contains a class of User with FirstName property inside. The goal is to have a user control which can be bound to any path. I know it must be super easy, but I'm very knew to that technology and I couldn't find the resolution.