WPF Databinding problem

Posted by costin on Stack Overflow See other posts from Stack Overflow or by costin
Published on 2011-01-11T15:29:38Z Indexed on 2011/01/11 15:53 UTC
Read the original article Hit count: 416

Filed under:
|
|
|

Hi, I'm new to WPF and I have some difficulties when I'm trying to populate a ListView with a list of custom objects.

internal class ApplicationCode
{
    public int Code { get; set; }

    public IEnumerable<string> InstrumentCodes { get; set; }
}

I have a list of ApplicationCode which I set to ItemsSource to a ListView. I need to display the ApplicationCode.Code as a string and for the rest of the columns a check box which can be checked/unchecked depending if the column name is contained in the InstrumentCodes collection.

In order to set the check box I use a converter on databinding:

<DataTemplate x:Key="InstrumentCodeTemplate">
  <CheckBox IsEnabled="False" IsChecked="{Binding Mode=OneTime, Converter={StaticResource InstrumentSelectionConverter}}" />
</DataTemplate>

The problem I have is because I can't know which is the current column at the time of cell data binding and I can't set the ConverterParameter.

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
  ApplicationCode appCode = value as ApplicationCode;

  return appCode != null && appCode.InstrumentCodes.Contains(parameter.ToString());
}

There is a way to find out the column index or name? Or there is another way to solve this problem?

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf