Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
275
Databinding Groups and Content in Codebehind
posted

Hi

I have a ViewModel with a list of objects, custom type "Pane" to represent OutlookGroupBars. The Pane object holds items again custom type "MenuGroup" to represent "ContentGroups" within an OutlookGroupBar. The MenuGroup again holds items of type "MenuItems" ...

I want to bind this model to my view programmatically, how should i proceed?

Edit:

I found an example with databinding and modified it according to my needs. However i've got a problem with left indentation when i use a listbox inside the datatemplate. If i use a stackpanel there's no identation at all.

Datatemplate with ListBox:

        <DataTemplate x:Key="ItemTemplate">
            <ListBox ItemsSource="{Binding}" HorizontalContentAlignment="Stretch">
                <ListBox.Template>
                    <ControlTemplate TargetType="{x:Type ListBox}">
                        <Grid Margin="0">
                            <ScrollViewer Focusable="false">
                                <StackPanel Name="NavigationTreePanel" FocusManager.IsFocusScope="True" IsItemsHost="true"/>
                            </ScrollViewer>
                        </Grid>
                    </ControlTemplate>
                </ListBox.Template>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <uc:ExpanderList Title="{Binding Path=Name}" HeaderImage="{Binding Path=Image}" Style="{StaticResource ExpanderListStyle}" IsExpanded="True">
                            <uc:ExpanderList.ContentList>
                                <ListBox>
                                    <ListBoxItem Content="Logbuch"/>
                                </ListBox>
                            </uc:ExpanderList.ContentList>
                        </uc:ExpanderList>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </DataTemplate>

Datatemplate with StackPanel:

         <DataTemplate x:Key="ItemTemplate">
            <StackPanel DataContext="{Binding}" FocusManager.IsFocusScope="True">
                <uc:ExpanderList Title="{Binding Path=Name}" HeaderImage="{Binding Path=Image}" Style="{StaticResource ExpanderListStyle}" IsExpanded="True">
                    <uc:ExpanderList.ContentList>
                        <ListBox>
                            <ListBoxItem Content="Logbuch"/>
                        </ListBox>
                    </uc:ExpanderList.ContentList>
                </uc:ExpanderList>
            </StackPanel>
        </DataTemplate>

Problem with the StackPanel is, it just show one entry.

  • 9694
    posted

    Hello,

    I apologize no one has responded to this post until now. I'm not exactly sure what the problem is. Are you saying that the last DataTemplate in your post does not work. If you have solved this, please let us know your solution. If not, is this something you could make a sample to illustrate the problem with?

    Thank you,