Guten Morgen,
ich habe aktuell ein Projekt, für welches ich in WPF das MVVM-Pattern benutzen muss(Was nicht gerade einfach ist, wenn man vorher nie mit WPF o.ä gearbeitet hat
.
Nun habe ich ein Problem, ich muss an eine ComboBox ein Objekt binden bzw die Property des Objektes.
Laut Google geht dies relativ einfach via
<ComboBox ItemsSource="{Binding location.name, UpdateSourceTrigger=PropertyChanged}"[...], jedoch scheint dies bei mir nicht so recht zu wollen.
Hier mal ein paar Ausschnitte aus meinem Code.
XAML des Controls:
XML-Daten
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
| x:Class="StandortbeschreibungNEW.Controls.ucStandortControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:myViewModels="clr-namespace:StandortbeschreibungNEW.ViewModels" d:DataContext="{d:DesignInstance myViewModels:vmStandort}" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<Grid> <ComboBox ItemsSource="{Binding location.name, UpdateSourceTrigger=PropertyChanged}" x:Name="comboBox" HorizontalAlignment="Left" Margin="170,10,0,0" VerticalAlignment="Top" Width="200" SelectedValuePath="{Binding /}" /> </Grid>
</UserControl> |
Der relevante Teil des Models:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
| public class mStandort : Model {
private string _name = "Hallo"; public string name { get { return _name; } set { _name = value; RaisePropertyChanged(() => name); } } |
und hier ein Ausschnitt aus der ViewModel
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
| public class vmStandort : ViewModel { public vmStandort() { init(); mStandort location = new mStandort(); location.name = "Gr. Standortbeschreibung"; }
private void init() { LoadHeadNodes(); if (HeadNodes != null) { LoadChildNodes(HeadNodes); } } [...] } |
Hoffe mir kann jemand weiterhelfen,
MfG
Ps: Alles zur Entwicklung grafischer Oberflächen mit der Windows
Presentiation Foundation (Windows.Controls-Namespace), XAML, Silverlight, XBAP - Das markierte "i" ist zu viel, sorry