Problema wpf usando propriedades de dependência em um UserControl
Eu fiz um UserControl que se destina a ser atualizado uma vez a cada poucos segundos com dados de uma porta serial. Este UserControl deve ser muito simples, consistindo de um Label para um nome de campo e outro Label contendo o valor do campo. Eu digo quedevemos seja simples, mas não funciona. Ele não é atualizado e nem exibe o nome do campo.
Abaixo está o código:
public partial class LabeledField : UserControl {
public LabeledField() {
InitializeComponent();
}
public string fieldName {
get { return fieldNameLabel.Content.ToString(); }
set { fieldNameLabel.Content = value; }
}
public string fieldValue {
get { return (string)GetValue(fieldValueProperty); }
set { SetValue(fieldValueProperty, value); }
}
public static readonly DependencyProperty fieldValueProperty =
DependencyProperty.Register(
"fieldValue",
typeof(string),
typeof(LabeledField),
new FrameworkPropertyMetadata(
"No Data"
)
)
;
}
Aqui está o XAML:
<UserControl x:Class="DAS1.LabeledField" Name="LF"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Orientation="Horizontal">
<Label Width="100" Height="30" Background="Gray" Name="fieldNameLabel" />
<Label Width="100" Height="30" Background="Silver" Name="fieldValueLabel" Content="{Binding fieldValue}" />
</StackPanel>
E aqui está o XAML para a janela que faz referência ao UserControl. Primeiro o cabeçalho:
<Window x:Class="DAS1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:me="clr-namespace:DAS1"
Title="Window1" Height="580" Width="780">
Em seguida, o UserControl propriamente dito:
<me:LabeledField fieldName="Test" Width="200" Height="30" fieldValue="{Binding businessObjectField}"/>
Se eu soubesse de uma pergunta mais específica para perguntar, eu faria - mas alguém pode me dizer por que isso não funciona?