I created a custom UserControl named EditUserInfo, that includes a DataForm control. In the UserControl I created a Dependency Property of type UserInformation class named CurrentItem.
The MainPage contains this user control, and in it's Loaded event I set UserControl's CurrentItem property to a newly created UserInformation object.
The UserInformation class is decorated with attributes for displays. When I run the application, the dataform genarates only the header but labels and textboxes missing. When I use the dataform individually in a page everything works well.
Here is the CurrentItem dependency Property:
public partial class UserinfoEditControl : UserControl { public UserinfoEditControl() { // Required to initialize variables InitializeComponent(); }
public UserInformation CurrentItem
{
get { return (UserInformation)GetValue(CurrentItemProperty); }
set { SetValue(CurrentItemProperty, value); }
}
public static readonly DependencyProperty CurrentItemProperty =
DependencyProperty.Register("CurrentItem", typeof(UserInformation), typeof(UserinfoEditControl), null);}
Here is the declaration of the UserControl, the DataContext set to RelativeResource Self:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
mc:Ignorable="d"
x:Class="WebSzamla.Controls.UserinfoEditControl"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
d:DesignWidth="245" d:DesignHeight="93">
In the DataTemplate I set the DatatBindigs:
<DataTemplate x:Key="RegistrationEditTemplate">
<StackPanel VerticalAlignment="Top" MinWidth="400" >
<toolkit:DataField >
<TextBox Text="{Binding email_address, Mode=TwoWay}" />
</toolkit:DataField>
<toolkit:DataField >
<PasswordBox Password="{Binding password, Mode=TwoWay}" />
</toolkit:DataField>
<toolkit:DataField >
<PasswordBox Password="{Binding confirm_password, Mode=TwoWay}" />
</toolkit:DataField>
<toolkit:DataField >
<TextBox Text="{Binding security_question, Mode=TwoWay}" />
</toolkit:DataField>
<toolkit:DataField >
<PasswordBox Password="{Binding security_answer, Mode=TwoWay}" />
</toolkit:DataField>
</StackPanel>
</DataTemplate>
In the MainPage I inserted my UserControl and set it's currentItem property to a new UserInformation object:
public Registration()
{
InitializeComponent();
Loaded += (s, e) =>
{
EditUserInfo.CurrentItem = newUser;
};
}
Does anybody knows, why it doesn't work? Thanks in advance
Gabriel