Hello,
Currently I am working on converting a ComboBox into a XamMultiColumnComboEditor as I'm trying to enhance the functionality of a drop down to include more information per item.
The ComboBox in question looks like this:
<ComboBox Name="BankAccounts" Visibility="{Binding ShowAllPaymentFields, Converter = {StaticResource BooleanToVisibilityConverter}}" ItemsSource="{Binding Path=BankAccounts}" SelectedItem="{Binding CurrentPayment.BankAccount,Mode=TwoWay}"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Converter={StaticResource BankAccountDisplayConverter}}"/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox>
I have started on the XamMultiColumnComboEditor and this is what it looks like:
<ig:XamMultiColumnComboEditor x:Name="BankAccounts" Visibility="{Binding ShowAllPaymentFields, Converter = {StaticResource BooleanToVisibilityConverter}}" MinDropDownHeight="100" MinDropDownWidth="230" ItemsSource="{Binding Path=BankAccounts}" AutoGenerateColumns="False" DisplayMemberPath="AccountNumber" SelectedItem="{Binding CurrentPayment.BankAccount,Mode=TwoWay}"> <ig:XamMultiColumnComboEditor.Columns> <ig:TextComboColumn Key="AccountNumber"/> <ig:TextComboColumn Key="BankName"/> <ig:DateComboColumn Key="DateLastUsed"/> </ig:XamMultiColumnComboEditor.Columns> </ig:XamMultiColumnComboEditor>
My issue is that I do not know how to add the BankAccountDisplayConverter from the ComboBox above into the XamMultiColumnComboEditor. Does anyone have any insight on how to do this? Please let me know if you need clarification.
Thanks,
Alex
This worked perfectly! Thank you so much. Consider making another post on how to do this because I think this could be valuable for others. Especially when using XamMultiColumnComboEditor with converters.
Thanks again,
Hello Alex,
Thank you for the code and the detailed description.
You can retemplate the TextComboColumn, through the CellStyle . You can use the ComboCellControl's ContentControl and add the Converter.For example:
<ig:TextComboColumn Key="AccountNumber"> <ig:TextComboColumn.CellStyle> <Style TargetType="{x:Type ig:ComboCellControl}"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <ContentControl Content="{Binding DataContext, Converter={StaticResource BankAccountDisplayConverter}}" /> </DataTemplate> </Setter.Value> </Setter> </Style> </ig:TextComboColumn.CellStyle> </ig:TextComboColumn>
If you need further information concerning this functionality, please let me know.
I am using a normal WPF Grid inside of a GroupBox, not a XamDataGrid. The Grid definitions look like this:
<Grid> <Grid.RowDefinitions> <RowDefinition Height="30" /> <RowDefinition Height="30" /> <RowDefinition Height="30" /> <RowDefinition Height="30" /> <RowDefinition Height="30" /> <RowDefinition Height="30" /> <RowDefinition Height="30" /> <RowDefinition Height="30" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="200" /> <ColumnDefinition Width="200" /> <ColumnDefinition Width="120" /> <ColumnDefinition Width="110" /> <ColumnDefinition Width="220" /> <ColumnDefinition/> </Grid.ColumnDefinitions>
Not that that matters much to you but just to give you a better idea of what the project is like.
The XamMultiColumnComboEditor is in a Border like this:
<Border Grid.Row="1" Grid.Column="1" Margin="5,0" BorderThickness="1" BorderBrush="{Binding ViewModelRef, Converter={StaticResource BorderValidationColorConverter}, ConverterParameter='BankAccount'}" >
We use it for validation.
I hope this is enough information for you.
Thank you for the converter code, you have sent.
Do you use the XamMultiColumnComboEditor as a field in XamDataGrid?
If you can, upload a small isolated sample, which implements the functionality you want to achieve. You can send it as attached zip file. Having this information will help me to further investigate this for you.
Thank you, although that is the correct way to do it, now I'm facing type conversion issues in the Converter which you requested so I'll give you a code snippet of that:
class BankAccountDisplayConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null && value !="") { var bankAccount = (BankAccount) value; var canSeeAllDigits = App.CurrentPaymentSession.CurrentCollectionRep.CanSeeAllDigitsOnBankAccounts == 1; var displayString =bankAccount.GetDisplayString(canSeeAllDigits); return displayString; } else { return ""; } }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return value; } }}
The converter expects a BankAccount object to get passed into "value" and instead the AccountNumber string gets passed in which causes a cast exception. Any way you know of remedying this and passing in the object itself rather than the AccountNumber string?