views:

326

answers:

2

In my application using DataTemplate mechanism I insert into ListBox item another listbox. But is it possible that when selected one listboxitem in parent listbox, the focus may be on another parent listboxitem's child (see picture)

Pic

How to do: if one of child listbox in focus (one item from them selected), then parent listboxitem being selected to? Using binding or templating

<DataTemplate x:Key="NotesListBoxDataTemplate" DataType="Note">
    <StackPanel Orientation="Vertical">

        <StackPanel Orientation="Horizontal">
            <TextBox Text="{Binding Path=Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
            <my:DatePicker Height="25" Name="datePicker1" Width="115" xmlns:my="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit" 
                           SelectedDate="{Binding LastEdit,
                                                  Mode = TwoWay}" />
        </StackPanel>
        <TextBox Text="{Binding Path=Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>

        <StackPanel Orientation="Horizontal">
            <ListBox Name="ImagesListBox"  SelectedIndex="{Binding Mode=OneWayToSource, Source={StaticResource progParameters}, Path=SelectedImage, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Path=Images}" ItemTemplate="{StaticResource NotesListBoxImagesTemplate}" Style="{StaticResource HorizontalListBox}">
            </ListBox>
            <StackPanel Orientation="Vertical">
                <Button Name="AddImageButon" Content="+" Click="AddImageButon_Click"></Button>
                <Button Name="RemoveImageButon" Content="-" Click="RemoveImageButon_Click"></Button>
            </StackPanel>

        </StackPanel>

    </StackPanel>
</DataTemplate>
A: 

I have the same problem. Maybe you already found solution?

Dmitry
Not yet. Just postponed this problem
Evl-ntnt
+1  A: 

On the parent ListBox set property IsSynchronizedWithCurrentItem to true, then in the inner ListBoxes set the SelectedItem property to "{Binding SelectedItem ElementName=lbParent}".

Consider using a Converter to help you get specific data that is not accessible thru xaml or if you need to do some caculations.

Hope this helps.

Shimmy