I have a usercontrol like this:
<UserControl x:Class="MySample.customtextbox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="20" d:DesignWidth="300">
<Grid>
<TextBox x:Name="Ytextbox" Background="Yellow"/>
</Grid>
</UserControl>
<CT:customtextbox Text="{binding mypropertyinviewmodel}"/>
DependencyProperty
public static readonly DependencyProperty InfoTextProperty =
DependencyProperty.Register("InfoText", typeof(string), typeof(customtextbox), new FrameworkPropertyMetadata(false));
public string InfoText
{
get { return (string)GetValue(InfoTextProperty);}
set
{
SetValue(InfoTextProperty, value);
}
}
Error 1 Cannot create an instance of "customtextbox".
new FrameworkPropertyMetadata(false)
You cannot set the default value of a string
property to false
(which of course is a bool
).
There may be some other problems (e.g. you have no binding on the TextBox
in the user coontrol declaration and you try to set a property you did not register where you create an instance) but for those you should search SO.