how do I convert string values to integers and back using IValueConverter.
I have a database that consist of two tables, table CompanyX and table DeptY.
Table CompanyX has field ID, firstName, lastName, Email, Phone.
Table DeptY has field dID, Roles.
DeptY dID is foreign key To CompanyX ID.
//To cut the story short this is my ItemTemplate below:
<application.resources>
<datatemplate x:key="myTemplate" xmlns:x="#unknown">
<wrappanel horizontalalignment="Stretch">
<textblock text="{Binding FirstName}" />
<Label />
<textblock text="{Binding LastName}" />
</wrappanel>
</datatemplate>
</application.resources>
//My ComboBox:
<combobox height="23" horizontalalignment="Right" margin="0,90,267,0" name="cboID" itemssource="{Binding}" displaymemberpath="" verticalalignment="Top" width="208" itemtemplate="{StaticResource myTemplate}" />
//My DataGrid:
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<textblock text="{Binding Path=TID, Converter={StaticResource myConverter}}" />
</datatemplate>
</datagridtemplatecolumn.celltemplate>
//And my IValueConverter:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string a = (string)value;
int b;
int.TryParse(a, out b);
return b;
}
public object ConvertBack(object value, Type targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
Can someone help please