Hi All,

I'm trying to bind a textbox to a listbox's selected.Content properties.
The listbox displays the items as designed in the datatemplate.
But I can't get a textbox to display one/any of the selectedItems properties.

DataTemplate

<DataTemplate x:Key="dt_Afloeser" >
            <Border BorderBrush="Black" BorderThickness="0.5" CornerRadius="2" Margin="2,2,2,2">
                <DockPanel HorizontalAlignment="Center">
                    <TextBlock Name="navn" Text="{Binding Path=navn}" Margin="2,2,2,2" HorizontalAlignment="Left" VerticalAlignment="Center" TextWrapping="WrapWithOverflow" />
                    <TextBlock Width="20"/>
                    <TextBlock Name="telefonNr"  Text="{Binding Path=telefonNr}" Margin="2,2,10,2" Width="auto" HorizontalAlignment="Left"  VerticalAlignment="Center" TextWrapping="WrapWithOverflow" />
                </DockPanel>
            </Border>
        </DataTemplate>

The DataContext for the Listbox is set in code.

<ListBox Name="lb_Afloesere" ItemsSource="{Binding}" ItemTemplate="{StaticResource dt_Afloeser}" IsEnabled="True" />

This only shows namespace.Afloeser

<TextBox Text="{Binding ElementName=lb_Afloesere, Path=SelectedItem}" Name="tb_navn" Margin="0,0,0,0" Height="26" ></TextBox>

if I add ".Content" I get nothing, and in desperation I have tried "Content.XXX" and "Content/XXX" without any success.

Hope someone can point me in the right direction.

Thanks
- Henning M

Ok, as so many times before. When you keep on trying you find a solution.

First I had to set SelectedItem="{Binding Path=SelectedItem}" in the Listbox. Then in the TextBox I had to set the Path=SelectedItem.navn and everything worked :)

Hope this will help someone else ..

- Henning M.

Hi All,

I'm trying to bind a textbox to a listbox's selected.Content properties.
The listbox displays the items as designed in the datatemplate.
But I can't get a textbox to display one/any of the selectedItems properties.

DataTemplate

<DataTemplate x:Key="dt_Afloeser" >
            <Border BorderBrush="Black" BorderThickness="0.5" CornerRadius="2" Margin="2,2,2,2">
                <DockPanel HorizontalAlignment="Center">
                    <TextBlock Name="navn" Text="{Binding Path=navn}" Margin="2,2,2,2" HorizontalAlignment="Left" VerticalAlignment="Center" TextWrapping="WrapWithOverflow" />
                    <TextBlock Width="20"/>
                    <TextBlock Name="telefonNr"  Text="{Binding Path=telefonNr}" Margin="2,2,10,2" Width="auto" HorizontalAlignment="Left"  VerticalAlignment="Center" TextWrapping="WrapWithOverflow" />
                </DockPanel>
            </Border>
        </DataTemplate>

The DataContext for the Listbox is set in code.

<ListBox Name="lb_Afloesere" ItemsSource="{Binding}" ItemTemplate="{StaticResource dt_Afloeser}" IsEnabled="True" />

This only shows namespace.Afloeser

<TextBox Text="{Binding ElementName=lb_Afloesere, Path=SelectedItem}" Name="tb_navn" Margin="0,0,0,0" Height="26" ></TextBox>

if I add ".Content" I get nothing, and in desperation I have tried "Content.XXX" and "Content/XXX" without any success.

Hope someone can point me in the right direction.

Thanks
- Henning M

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.