Das MASTER-Binding

 

 

MainWindow.xaml:

<Window x:Class="MasterBinding.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MasterBinding"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" x:Name="Window">
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<ListBox x:Name="lbName" Width="250" Height="150" ItemsSource="{Binding Persons, ElementName=Window}" DisplayMemberPath="Name"/>
<Border Width="250" Height="150" Background="LightGray">
<TextBlock Text="{Binding ElementName=lbName, Path=SelectedItem.Web}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="ExtraBlack" />
</Border>
</StackPanel>
</Grid>
</Window>

 

MainWindow.xaml.cs:

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MasterBinding
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

public ObservableCollection<Person> Persons { get; set; }

public MainWindow()
{
Persons = new ObservableCollection<Person>();

Persons.Add(new Person { Name = "Han Solo", Web = "www.Millenium-Falke.de" });
Persons.Add(new Person { Name = "Darth Vader", Web = "www.Todesstern.de" });
Persons.Add(new Person { Name = "Der Imperator", Web = "www.Imperium.org" });

 

InitializeComponent();
}
}
}


Person.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MasterBinding
{
public class Person
{
public string Name { get; set; }
public string Web { get; set; }
}
}

Top