How to bind a ComboBox in a DataTemplate ~ non-MVVM way?

2 posts, 0 answers
  1. Dexter
    Dexter avatar
    34 posts
    Member since:
    Dec 2012

    Posted 12 Aug 2014 Link to this post

    Hello, I would like to enquire on a solution to as per title.

    If the ComboBox is simply a GridViewColumn, it would had been straight-forward like this:
    ((GridViewComboBoxColumn)gridPrintOption.Columns["PrintCode"]).ItemsSource = listPrintCode;

    But now that it is in a DataTemplate (of a ListBox), it is more complicated as there's no direct means of accessing the controls.
    Below are the codes of what I currently have, simplified:

    <telerik:RadListBox Grid.Row="0" Grid.Column="2" Margin="0, 5, 5, 5"
                x:Name="listBoxIssue" HorizontalAlignment="Left" VerticalAlignment="Top"
                Height="690" Width="793"
                ItemTemplate="{StaticResource lbIssueTemplate}" ItemsSource="{Binding}">
    <DataTemplate x:Key="lbIssueTemplate">
            <Grid Margin="0" Width="Auto">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>            
                <ComboBox x:Name="PrintCode" Grid.Row="0" Grid.Column="2" ItemsSource="{Binding}"
                          SelectedValuePath="PrintCode" DisplayMemberPath="PrintCode" />
            </Grid>
        </DataTemplate>

    So basically I'm binding 2 different objects here. 1 to the ListBox, and 1 to the ComboBox. The object that binds to the ListBox has a property which is used as the "SelectedValuePath" of the ComboBox, while the object that binds to ComboBox simply provide the ComboBox with the list of options available for users to choose upon drop-down. Everything is fine as it is, but the only problem is I don't know how to bind the object to the ComboBox in non-MVVM way. If it were a GridViewColumn, I would have solved the problem as shown in my 1st code block.
  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 14 Aug 2014 Link to this post

    Hi Dexter,

    As this is more of a general question, not specifically related to Telerik WPF controls ( RadListBox can be replaced with any ItemsControls), I would suggest that you check the following threads on StackOverflow:

    Regards,
    Yana
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top