我有一个包含转换器的项目。当我点击DGKraj(众多ComboBox中的一个)并在初始化期间自动调用转换器。如何仅在初始化期间调用转换器?
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();
}
}
XAML
<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>