How can I make a binding to one instance of a class? I have a combobox and if I change the selectedItem in the combobox two 2 input field's should be fillied with the propertys of the instance of the object.
Here is my wpf code:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Bearbeiten:" Style="{StaticResource TextBlockHeader}" Grid.Row="0"/>
<ComboBox ItemsSource="{Binding LinkList}" DisplayMemberPath="DisplayName" Style="{StaticResource defaultComboBox}" Grid.Row="1"/>
<Separator Style="{StaticResource defaultSeperator}" Grid.Row="2"/>
<TextBlock Text="DisplayName:" Style="{StaticResource TextBlockHeader}" Grid.Row="3"/>
<TextBox Name="linkDisplayName" Style="{StaticResource NormalTextBox}" Grid.Row="4"/>
<TextBlock Text="URL" Style="{StaticResource TextBlockHeader}" Grid.Row="5"/>
<TextBox Name="linkUrl" Style="{StaticResource LargeTextBox}" Grid.Row="6"/>
</Grid>
I've set the DataContext in the codebehind file (mainWindow.xaml.cs). Here is the code of the file:
public class mainWindow : MetroWindow
{
public LinkManager LinkManager { get; set; }
public mainWindow()
{
InitializeComponent();
this.DataContext = this.LinkManager;
}
}
The LinkManager.cs:
public class LinkManager
{
public ObservableCollection<Link> LinkList { get; set; }
}
And at the end the Link.cs
public class Link
{
private string _displayName;
public string DisplayName
{
get { return this._displayName; }
set { this._displayName = value; }
}
private string _url;
public string Url
{
get { return this._url; }
set { this._url = value; }
}
}
The ComboBox binding is working well:
but the inputfields are still empty (that's logic...). How can I fill them with the propertys of the selected instance of the object in the combobox?
Any Suggestions? Thanks!