Hi,
I have this user control…
<UserControl x:Class=“SilverlightApplication.UserControls.FormItem_TextBox”
xmlns=“http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=“http://schemas.microsoft.com/winfx/2006/xaml”
>
<StackPanel Orientation="Vertical" >
<TextBlock x:Name="lbCaption" Style="{StaticResource TextBlockStyle}" />
<TextBox x:Name="tbItem" Style="{StaticResource TextBoxStyle}" />
</StackPanel>
</UserControl>
…which has this code behind…
public partial class FormItem_TextBox : UserControl
{
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(String), typeof(FormItem_TextBox), new PropertyMetadata(TextChanged));
public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register("Caption", typeof(String), typeof(FormItem_TextBox), new PropertyMetadata(CaptionChanged));
public String Text
{
get { return (String)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public String Caption
{
get { return (String)GetValue(CaptionProperty); }
set { SetValue(CaptionProperty, value); }
}
private static void TextChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
FormItem_TextBox item = (source as FormItem_TextBox);
item.tbItem.Text = e.NewValue.ToString();
}
private static void CaptionChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
FormItem_TextBox item = (source as FormItem_TextBox);
item.lbCaption.Text = e.NewValue.ToString();
}
public FormItem_TextBox()
{
InitializeComponent();
}
}
How comes that when I attempt to TwoWay databind to the controls TextProperty, like so…
<UC:FormItem_TextBox Caption=“First Name: " Text=”{Binding Path=FirstName, Mode=TwoWay}" />
…it doesn’t play ball??
I know my MVVM stuff is OK because I have tested it on a simple text box, i.e.
<TextBox Text="{Binding Path=FirstName, Mode=TwoWay}" />
…and it works just fine.
Is there any other wiring up that is needed within my user control??
I am brand spanking new to silverlight/WPF, so please be gentle!!!
Many thanks for any responses.
ETFairfax