I'm writing an app where users enter records. I have a class that represents a record. Binding it to text fields works.
MainPage.xaml.cs:
public MainPage()
{
InitializeComponent();
// newExpense is of type ExpenseInfo
LayoutRoot.DataContext = newExpense;
}
ExpenseInfo.cs:
public class ExpenseInfo
{
public String Name { get; set; }
// ...
}
MainPage.xaml:
<TextBox Text="{Binding Name, Mode=TwoWay}" Height="23" HorizontalAlignment="Left" Margin="13,205,0,0" Name="NameTextBox" VerticalAlignment="Top" Width="74" />
This works to get and set the input. Two questions:
What if I have a ListBox, whose members I'm trying to represent with an ICollection
in ExpenseInfo
? Can I automatically bind it? What if I'm using a ComboBox instead?
Sometimes, I want ExpenseInfo to change the input controls. How can I do this? (For example, if the user types "3$0" in the "Cost" text box, I'd like to automatically change it to "$30".)
Thanks. I'm new to Silverlight 4.