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

RadCoursel: databinding to a textbox in a CarouselItems

2 Answers 31 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Craig Cote
Top achievements
Rank 2
Craig Cote asked on 11 Jul 2008, 07:56 AM

The ItemSource of my RadCarousel is a datatable (which is capable of databinding according to MS).  I've added a TextBox control to my XAML definition for the ControlTemplate for the CarouselDataRecordPresenter as per the following code:

<

StackPanel Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" >
    
<TextBox Text="{Binding Path=Fields[Answer].Value, Mode=TwoWay,
        
UpdateSourceTrigger=PropertyChanged}" FontSize="12" Foreground="Black"
        
Width="216" />
</StackPanel>

The carousel is displaying the values from the DataTable fine, but the TextBox.Text is not successfully updating the DataTable's "Answer" column.

Note that I have specified TwoWay binding (should not be necessary because that is the default mode for the TextBox control) as well as the UpdateSourceTrigger property of the binding (just to test).

This is a really annoying problem!  Now I have to try to programatically determine what the TextBox.Text value is and manually update the datasource.  Any direction on where to start doing so would be most helpful.

2 Answers, 1 is accepted

Sort by
0
Craig Cote
Top achievements
Rank 2
answered on 12 Jul 2008, 06:38 AM
I still think that there is an issue here (and of the three posts I made originally, this is the only one that has not been responded to).  But I've come up with the following work-around:

I bound the "Tag" property of the TextBox to the identity field of the record, added an event handler for the TextChanged event.  Using that "Tag" value, I do a select on my data source, then update the appropriate field with the TextBox's Text value.

(I tried to use the MouseLeave event to avoid processing the EventHandler so often, but when I moved my mouse away from the TextBox to click on a button to signal that I was ready to move to the next stage, the last TextBox I was on did not fire the event!)
0
Milan
Telerik team
answered on 14 Jul 2008, 07:55 AM
Hi Craig Cote,

At this moment we do not directly support data editing in our RadCarousel but we can use a trick to enable this functionality. Usually the RadCarousel will create the data presenters that are needed to visualize your data entities but you can turn that functionality off by setting the AutogenerateDataPresenters property to false. If this property is set to false you can provide a DataTemplate that will define how your data will be displayed. Usually one would use this approach to provide custom styling but now we will simply use it to get access to the original data entities. Here is a sample XAML code that has a global DataTemplate that is targeting the CustomersRow data entity of the NorthWind database.

<Grid> 
    <Grid.Resources> 
        <DataTemplate DataType="{x:Type test:NWindDataSet+CustomersRow}"
            <StackPanel> 
                <TextBox Text="{Binding Path=CustomerID}"/> 
            </StackPanel> 
        </DataTemplate> 
    </Grid.Resources> 
    <Telerik:RadCarousel AutoGenerateDataPresenters="False"/> 
</Grid> 

The benefit of this approach is that you are directly accessing the properties of the data entities and you can modify them.
Now the TextBox is directly bound to the CustomerID property and any changes will be propagated. I hope that this workaround works for you.

Sincerely yours,
Milan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Craig Cote
Top achievements
Rank 2
Answers by
Craig Cote
Top achievements
Rank 2
Milan
Telerik team
Share this question
or