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

Binding doesn't work normally

1 Answer 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Алексей
Top achievements
Rank 1
Алексей asked on 10 May 2018, 02:48 PM

Hi.

I think I have a problem with binding.

I use a RadGridView with 3 columns and binding. I set DataContext in code behind and use it in binding here.

I also use TextBlockWithSearchProperty. It's common  TextBlock with my custom property SearchText, it works normally.

The problem is that GridView create a few TextBlockWithSearchProperty objects and  view works normal. I can see a data that I show in view, but in code behind  property Text (TextBlockWithSearchProperty) is equal to "" and DataContext is equal to null. I don't understand why?

How can I fix it? Or what I do wrong?

<telerik:RadGridView Name="GridView"  Margin="5" 
                              AutoGenerateColumns="False" ItemsSource="{Binding Path=SelecteDay.Items}">


            <telerik:RadGridView.Columns>

                <telerik:GridViewDataColumn Header="Time"

                                            DataMemberBinding="{Binding Time, StringFormat=\{0:hh\\:mm\}}"
                                            CellEditTemplate="{StaticResource TimePicker}" Width="100" />


                <telerik:GridViewDataColumn Header="Text" x:Name="TextColumn" 
                                            DataMemberBinding="{Binding Text, UpdateSourceTrigger=PropertyChanged}" 
                                            Width="*"  IsFilterable="True" FilterMemberPath="Text"> 
                    
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate >
                            <infrastructure:TextBlockWithSearchProperty Text="{Binding Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                                                        SearchText="{Binding RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}},                                                                                                Path=DataContext.SearchText, Mode=OneWay}"
                                                                        d:DataContext="{Binding}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>

        </telerik:RadGridView>

1 Answer, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
Iron
answered on 25 Apr 2021, 10:52 AM

I have an identical scenario, the binding for the search text is never set.  It's always "" in my dependency property callbacks for my custom control (which highlights searched text just like yours).

Did you ever get a solution for this?

Tags
GridView
Asked by
Алексей
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Iron
Share this question
or