Folgendes Problem habe ich aktuell.
ich habe eine Observable Collection<Adresse> welche ich an eine Listbox binde.
Durch anklicken eines eintrages (SelecetedItem) wird dieser Inhalt an ein Property Übergeben ( AddData von Adressdaten).
Dieser Inhalt von AddData wird dann an verschiedene Textboxen gebunden. Soweit klappt auch alles.
jetzt soll aber für Addresstyp anstelle einer Textbox eine vorgefüllte Combobox verwendet werden.
an diese ist der Inhalt von AddTyp gebunden.
(Addtyp.Adresstyp sowie AddTyp.ID_Adresstyp).
Wie bekomme ich das hin, dass er mir beim auswählen aus der Liste automatisch den Richtigen wert in der Combobox zuweist?
Bin da etwas verzweifelt.
<DockPanel Grid.Row="5" Grid.Column="1" Margin="5,5,5,5" Visibility="{Binding Anzeigeändern, Converter={StaticResource bool2vis}, Mode=OneWay}">
<ComboBox ItemsSource="{Binding Adresstypenliste}" SelectedItem="{Binding AddTyp.Adresstyp}" SelectedValue="{Binding AddData.AdressTyp}" HorizontalAlignment="Left" Height="25" Width="250" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Adresstyp}" VerticalAlignment="Center" HorizontalAlignment="Left" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DockPanel>
<ListBox ItemsSource="{Binding Adressdatenliste}" SelectedItem="{Binding AddData}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Straße}" Margin="5,0,5,0"/>
<TextBlock Text="{Binding Hausnummer}" Margin="5,0,5,0"/>
<TextBlock Text="{Binding Plz}" Margin="5,0,5,0"/>
<TextBlock Text="{Binding Ort}" Margin="5,0,5,0"/>
<TextBlock Text="{Binding Land}" Margin="5,0,5,0"/>
<TextBlock Text="{Binding AdressTyp}" Margin="5,0,5,0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
private Adressdaten addData = new Adressdaten();
public Adressdaten AddData
{
get => addData;
set
{
if (value != addData)
{
addData = value;
AddTyp.Adresstyp = Adressdatenliste.FirstOrDefault(x => x.AdressTyp == AddTyp.Adresstyp).ToString(); // Funktioniert nicht
RaisePropertyChanged();
ChangeAdressData = true;
}
}
}
private Adresstypen addtyp = new Adresstypen();
public Adresstypen AddTyp
{
get => addtyp;
set
{
if (value != addtyp)
{
addtyp = value;
RaisePropertyChanged();
}
}
}
class Adresstypen : NotifyableBaseObject
{
private string adresstyp, id_Adresstyp;
public string Adresstyp
{
get => adresstyp;
set
{
if(value!= adresstyp)
{
adresstyp = value;
RaisePropertyChanged();
}
}
}
public string ID_Adresstyp
{
get => id_Adresstyp;
set
{
if(value != id_Adresstyp)
{
id_Adresstyp = value;
RaisePropertyChanged();
}
}
}
}