0

I have a project, which contain converter. After completion of the ContinentSelectionChanged method call, is called automatically the converter. How can I change the value that converter gets?

XAML

                        <DataGridComboBoxColumn x:Name="DGKontynent" Header="Kontynent" Width="120" CanUserSort="False" SelectedItemBinding="{Binding Kontynent}" >
                            <DataGridComboBoxColumn.EditingElementStyle>
                                <Style TargetType="ComboBox">
                                    <EventSetter Event="SelectionChanged" Handler="ContinentSelectionChanged" />
                                </Style>
                            </DataGridComboBoxColumn.EditingElementStyle>
                        </DataGridComboBoxColumn>

                        <DataGridComboBoxColumn x:Name="DGKraj" Header="Kraj" Width="120" CanUserSort="False" SelectedValueBinding="{Binding Kraj}" >
                            <DataGridComboBoxColumn.ElementStyle>
                                <Style TargetType="ComboBox">
                                    <Setter Property="ItemsSource" Value="{Binding Path=Kontynent,Converter={StaticResource CountryConverter}}"/>
                                    <Setter Property="SelectedValue" Value="{Binding Path=Kraj}"/>
                                </Style>
                            </DataGridComboBoxColumn.ElementStyle>
                            <DataGridComboBoxColumn.EditingElementStyle>
                                <Style TargetType="ComboBox">
                                    <Setter Property="ItemsSource" Value="{Binding Path=Kontynent,Converter={StaticResource CountryConverter}}" />
                                    <Setter Property="SelectedValue" Value="{Binding Path=Kraj}"/>      
                                </Style>
                            </DataGridComboBoxColumn.EditingElementStyle>
                        </DataGridComboBoxColumn>

C# Converter

    public class CountrySingleConverter : IValueConverter
    {
        Funkcje FK = new Funkcje();
        List<string> kraje = new List<string>();

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {    
            if (value != null && !string.IsNullOrWhiteSpace(value.ToString()))
            { 
                kraje = FK.kraj_wybierz(value.ToString(), Edycja.dgKraj);
                    return kraje;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }      
    }

C#

List<string> l3 = new List<string>();
static string kontynent_tmp;
private void ContinentSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    Xceed.Wpf.Toolkit.MessageBox.Show(DGKraj.SelectedValueBinding.);
    string kontynent = null;
    l4.Clear();

    var row = ZdarzeniaDataGrid.GetSelectedRow();

    DataGridCell cell = ZdarzeniaDataGrid.GetCell(row, 5);

    if (cell != null)
    {
        ComboBox combo = GetVisualChild<ComboBox>(cell);
        if (combo != null)
        {
            if (combo.SelectedValue != null)
            {
                kontynent = combo.SelectedValue.ToString();
                kontynent_tmp = kontynent;
            }
            else
            {
                kontynent = kontynent_tmp;
            }
        }
    }

    l3 = FK.kraj_wybierz(kontynent, DGKraj);

    DataGridCell cell3 = ZdarzeniaDataGrid.GetCell(row, 6);

    if (cell3 != null)
    {
        ComboBox combo3 = GetVisualChild<ComboBox>(cell3);
        if (combo3 != null)
        {
            combo3.ItemsSource = l3;
        }
    }
}
  • You must give more detail on what you want to do. I added my answer on a guess what you want. – BlueM Mar 17 '14 at 14:52

1 Answers1

0

The value sent to the converter is always what you bound to in {Binding}. If you want to bind to something else you must specify that.

e.g.

{Binding Kontynent.Name}
BlueM
  • 6,523
  • 1
  • 25
  • 30