У меня есть пользовательский контроль, который я использую в нескольких местах в моем проекте.Я использую его для отображения поля, но макет отличается для разных типов полей ... Он отлично работает, когда я использую его в коде и вне любых шаблонов, но не работает, когда я использую его в табличке данных для моегоПосмотреть список.Единственное, что он делает - это изменяет макет, но не показывает значения (например, имя и описание).
Я хочу связать свойства, такие как Title, Description & Type, которые являются присоединенными свойствами, но они некажется, не работает в табличке данных ... Это свойства:
public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(ucBoardField), new UIPropertyMetadata("", new PropertyChangedCallback(UpdateTitle)));
public string Description
{
get { return (string)GetValue(DescriptionProperty); }
set { SetValue(DescriptionProperty, value); }
}
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(string), typeof(ucBoardField), new UIPropertyMetadata("", new PropertyChangedCallback(UpdateDescription)));
public string FieldTypeDescription
{
get { return (string)GetValue(FieldTypeDescriptionProperty); }
set { SetValue(FieldTypeDescriptionProperty, value); }
}
public static readonly DependencyProperty FieldTypeDescriptionProperty =
DependencyProperty.Register("FieldTypeDescription", typeof(string), typeof(ucBoardField), new UIPropertyMetadata("street", new PropertyChangedCallback(UpdateFieldTypeDescription)));
И вот их методы обновления:
public static void UpdateTitle(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
{
ucBoardField bf = sender as ucBoardField;
if (bf == null) return;
if (bf.Field == null) bf.Field = new Field();
bf.Field.Title = (string)eventArgs.NewValue;
bf.lblExtraTax.Text = bf.lblStation.Text = bf.lblStreetname.Text = bf.lblUtility.Text = bf.Field.Title;
}
public static void UpdateDescription(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
{
ucBoardField bf = sender as ucBoardField;
if (bf == null) return;
if (bf.Field == null) bf.Field = new Field();
bf.Field.Description = (string)eventArgs.NewValue;
bf.lblCity.Text = bf.Field.Description;
}
public static void UpdateFieldTypeDescription(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
{
ucBoardField bf = sender as ucBoardField;
if (bf == null) return;
if (bf.Field == null) bf.Field = new Field();
if (bf.Field.FieldType == null) bf.Field.FieldType = new FieldType();
bf.Field.FieldType.Description = bf.FieldTypeDescription = (string)eventArgs.NewValue;
bf.ShowContent(); //updates layout
}
Они работают нормально, когда обращаются в коде, новсе, кроме FieldTypeDescription, показывают свои результаты в табличке данных, вот как я их связываю:
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<uc:ucBoardField
Id="{Binding Path=Field.Id}"
FieldTypeId="{Binding Path=Field.FieldTypeId}"
Title="{Binding Path=Field.Title}"
Description="{Binding Path=Field.Description}"
FieldTypeDescription="{Binding Path=FieldType.Description}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
На самом деле они работают, но данные не отображаются ... Кроме того, когда их привязка срабатывает, Я получаю сообщение об ошибке (или предупреждение):
System.Windows.Data Error: 40 : BindingExpression path error: 'Field' property not found on 'object' ''Field' (HashCode=64502806)'. BindingExpression:Path=Field.Title; DataItem='Field' (HashCode=64502806); target element is 'ucBoardField' (Name=''); target property is 'Title' (type 'String')
System.Windows.Data Error: 40 : BindingExpression path error: 'Field' property not found on 'object' ''Field' (HashCode=64502806)'. BindingExpression:Path=Field.Description; DataItem='Field' (HashCode=64502806); target element is 'ucBoardField' (Name=''); target property is 'Description' (type 'String')
Поле свойства - это просто объект со всей информацией о поле для отображения, которую я получаю с сервера.И это в моем списке:
System.Windows.Data Warning: 40 : BindingExpression path error: 'Title' property not found on 'object' ''TextBlock' (Name='lblTitle')'. BindingExpression:Path=Title; DataItem='TextBlock' (Name='lblTitle'); target element is 'TextBlock' (Name='lblTitle'); target property is 'Text' (type 'String')
System.Windows.Data Warning: 40 : BindingExpression path error: 'Description' property not found on 'object' ''TextBlock' (Name='lblDescription')'. BindingExpression:Path=Description; DataItem='TextBlock' (Name='lblDescription'); target element is 'TextBlock' (Name='lblDescription'); target property is 'Text' (type 'String')
Это не дает сбоя, однако ... Кто-нибудь знает, что я могу сделать неправильно, почему я получаю эти ошибки и как я могу их исправить?Заранее благодарю!