I can't figure out why I keep getting this error, and when I make a change to tb_Name
TextBox
in the GUI the Set in Name
never gets called.
System.Windows.Data Error: 40 : BindingExpression path error: 'Name' property not found on 'object' ''String' (HashCode=2106982518)'. BindingExpression:Path=Name; DataItem='String' (HashCode=2106982518); target element is 'TextBox' (Name='tb_Name'); target property is 'Text' (type 'String')
XAML
<UserControl
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"
xmlns:local="clr-namespace:ConfigStudioUI.Controls" x:Class="ConfigStudioUI.Controls.DeviceTypeTabCtrl"
mc:Ignorable="d" x:Name="DeviceTypeUC" Loaded="DeviceType_Loaded"
d:DesignHeight="400" d:DesignWidth="600" Background="#FF00C8FF"
>
<Grid>
<TabControl Background="#FF00FF99" FontSize="14"
TabStripPlacement="Left" Margin="0, 0, 0, 10" >
<TabItem Name="PropertiesTab" Header="Properties">
<Grid>
<Grid >
<TextBox Text="{Binding Source=DeviceType, Path=Name, Mode=TwoWay}"
TabIndex="0" x:Name="tb_Name" HorizontalAlignment="Stretch" Height="32"
Margin="159,28,5.2,0" VerticalAlignment="Top" />
</Grid>
</Grid>
</TabItem>
</TabControl>
</UserControl>
Code Behind
public partial class DeviceTypeTabCtrl : UserControl
{
public DeviceType DeviceType { get; set; }
public DeviceTypeTabCtrl(DeviceType deviceTypeObject, DeviceTypeGroup
deviceTypeGroupObject)
{
InitializeComponent();
DataContext = this;
this.DeviceType = new DeviceType();
this.DeviceType = deviceTypeObject;
this.tb_Name.Text = deviceTypeObject.Name;
this.DeviceType.DeviceTypeGroupGUID =
deviceTypeGroupObject.DeviceTypeGroupGUID;
}
}
public class DeviceType : INotifyPropertyChanged
{
/// <summary>
/// Name
/// </summary>
public string Name
{
get
{
return this.name;
}
set
{
if (this.name != value)
{
this.name = value;
NotifyPropertyChanged("Name");
}
}
}
}