I have next problem: i have a View:
<UserControl x:Class="WpfApplication1.UserControl1"
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="300" d:DesignWidth="300">
<Grid>
<TextBlock>
test
<TextBlock Text="{Binding TestingTest}"></TextBlock>
test
</TextBlock>
</Grid>
</UserControl>
with code-behind:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public string TestingTest
{
get { return (string)GetValue(TestingTestProperty); }
set { SetValue(TestingTestProperty, value); }
}
public static readonly DependencyProperty TestingTestProperty =
DependencyProperty.Register("TestingTest", typeof(string), typeof(UserControl1), new UIPropertyMetadata("testing test"));
}
and i try to use this view in my view with ViewModel:
<Window x:Class="WpfApplication1.MainWindow" Name="wnd"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WpfApplication1="clr-namespace:WpfApplication1" Title="MainWindow" Height="350" Width="525">
<Grid>
<WpfApplication1:UserControl1 TestingTest="{Binding ElementName=wnd, Path=Title}"></WpfApplication1:UserControl1>
</Grid>
ViewModel:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
public string GoGoGo
{
get
{
return "Test message";
}
}
}
but every time i got next message in Output window and dont see test message:
*System.Windows.Data Error: 40 : BindingExpression path error: ‘TestingTest’ property not found on ‘object’ ”UserControl1′ (Name=’my’)’. BindingExpression:Path=TestingText; DataItem=’UserControl1′ (Name=’my’); target element is ‘TextBlock’ (Name=”); target property is ‘Text’ (type ‘String’)
*
What do i wrong?
It’s a typo.
On your UserControl you have the property
TestingTestand on the WPF you haveTestingText(‘s’ and ‘x’)