This is a migrated thread and some comments may be shown as answers.

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

1 Answer 579 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dexter
Top achievements
Rank 1
Dexter asked on 12 Aug 2014, 01:21 PM
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.

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 14 Aug 2014, 01:53 PM
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.
 
Tags
General Discussions
Asked by
Dexter
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or