Binding header text

13 posts, 0 answers
  1. IT Development
    IT Development avatar
    25 posts
    Member since:
    Mar 2009

    Posted 05 Jul 2010 Link to this post

    Hello,

    For localization purposes I need to bind the header text of the radgridview.

    The button under the radgridview is showing the correct text.

    Why is the header text of the first column not showing anything?


    <StackPanel>

            <telerik:RadGridView AutoGenerateColumns="False" x:Name="RadGridViewGebruikers" ItemsSource="{Binding Users}" ShowGroupPanel="False" IsReadOnly="True">

                <telerik:RadGridView.Columns>

                    <telerik:GridViewDataColumn   DataMemberBinding="{Binding UserName}" Width="200">

                        <telerik:GridViewDataColumn.Header>

                            <TextBlock Text="{Binding ResourceGridHeaderGebruiker}"></TextBlock>

                        </telerik:GridViewDataColumn.Header>

                        </telerik:GridViewDataColumn>

                    <telerik:GridViewDataColumn Header="{Binding ResourceGridHeaderIsIngelogd}" DataMemberBinding="{Binding IsOnline}" MinWidth="200" Width="*"/>

                    <telerik:GridViewDataColumn Header="{Binding ResourceGridHeaderDatumActief}" DataMemberBinding="{Binding LastActivityDate}" MinWidth="200"/>

                </telerik:RadGridView.Columns>

                <telerikNavigation:RadContextMenu.ContextMenu>

                    <telerikNavigation:RadContextMenu Template="{StaticResource CrudContextMenu}">

                    </telerikNavigation:RadContextMenu>

                </telerikNavigation:RadContextMenu.ContextMenu>

            </telerik:RadGridView>

                               <Button Content="{Binding ResourceGridHeaderGebruiker}" />

            </StackPanel>

     

    Kind regards,

    Tim van Rooijen


  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 05 Jul 2010 Link to this post

    Hello Tim,

    The reason for the binding to fail is as follows :
    The DataContext of the header cell is the header string rather than the DataContext of RadGridView.
    To be able to bind you may need to expose the ResourceGridHeaderGebruiker property in a static resource .

    Sincerely yours,
    Pavel Pavlov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Alexey Oyun
    Alexey Oyun avatar
    74 posts
    Member since:
    Mar 2010

    Posted 10 Sep 2010 Link to this post

    Hi,
    Could you give small example of bindning object to header, please.
    Thanks, Alex.
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 13 Sep 2010 Link to this post

    Hi Alexey Oyun,

    I have prepared a small sample. There is one column with a header bound to a property of a small class.
    This approach may be extended to fit your scenario.

    Please note  that if you need to change the headers runtime , the class needs to implement the INotifyPropertyChanged interface. This way RadGridView update the header each time the property is changed.

    Kind regards,
    Pavel Pavlov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Alexey Oyun
    Alexey Oyun avatar
    74 posts
    Member since:
    Mar 2010

    Posted 13 Sep 2010 Link to this post

    Thank you, I thought I would have DataContext of Grid. Anyway your solution through resources my workout for me.
  7. Richard Koslik
    Richard Koslik avatar
    71 posts
    Member since:
    Apr 2010

    Posted 15 Oct 2010 Link to this post

    Hello!

    I also want to change the header, but I need a converter for displaying my text. How does this work! My problem is he does'nt call the converter, it is always displayed the FALLBACKVALUE!

    <telerik:RadGridView HorizontalAlignment="Left" Margin="23,46,0,0" Name="grdDisc" 
                         VerticalAlignment="Top" Height="275" Width="240" 
                         AutoGenerateColumns="False"
                         ItemsSource="{Binding tabMONDISC}" 
                         SelectedItem="{Binding SelItemMONDISC, Mode=TwoWay}" 
                         IsBusy="{Binding bIsLoading}" IsReadOnly="True" 
                         RowIndicatorVisibility="Collapsed">
      <telerik:RadGridView.Columns>
         <telerik:GridViewDataColumn DataMemberBinding="{Binding MONDISC_S_LETTER}" 
                     Width="100" Header="{Binding Path=iActiveLanguage
                     FallbackValue=LaufwerkFB, Converter={StaticResource 
                      localLngConverter}, ConverterParameter=4121}" />
      </telerik:RadGridView.Columns>
    </telerik:RadGridView>

    iActiveLanguage => aktuelle Sprache zur richtigen Darstellung der Texte
    FallbackValue => default value for development-modus
    localLngConverter => Converter for getting the right text
    ConverterParamter => number of the text

    Why is the FALLBACKVALUE displayed and not the converter called??

    Best regards,
    Richard
  8. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 15 Oct 2010 Link to this post

    Hello Richard Koslik,

    Which is the object that exposes the iActiveLanguage property ? 
    I believe the reason for the binding to fail is that  the object owning the iActiveLanguage property is not a DataContext for the header cells.

    Please let me know where this object is instantiated so I could help you further .

    Regards,
    Pavel Pavlov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Richard Koslik
    Richard Koslik avatar
    71 posts
    Member since:
    Apr 2010

    Posted 18 Oct 2010 Link to this post

    Hello!

    The property iActiveLanguage is not used for the converter. We only used it, because we needed a binding variable and it is created in the VieModel. For us important are converter, converterparameter and FallbackValue, so that we are able to get the right text displayed.

    I tried it with the static resource and it worked, but is there a simplier way so that I don't need an additional property?


    Best regards, Richard
  10. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 20 Oct 2010 Link to this post

    Hello Richard Koslik,

    I believe exposing the source which you are binding  to as a static resource  and using the "{Binding .., Source = {StaticResource ....  " syntax is the simplest  solution.

    Regards,
    Pavel Pavlov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Stephen
    Stephen avatar
    3 posts
    Member since:
    Dec 2010

    Posted 10 Dec 2010 Link to this post

    Hi,

    The above approach of using a static resource to connect to the class does not work for me, I think because I do no use a default constructor. The error i get is 'No matching constructor found on type 'myViewModel'. My viewModel's constructor takes in some interfaces as parameters. If I put in a default constructor in, I dont get the error, but my column headers are empty, I assume because it has created a new viewModle with the default constructor and not using my dataContext which has the correct column heading.

    An alternative way of doing this which I think should work is this: But it too fails to print anything in the header.
    <telerikG:GridViewDataColumn  Width="Auto" MinWidth="110" IsReadOnly="True">
                                                    <telerikG:GridViewDataColumn.HeaderCellStyle>
                                                        <Style TargetType="telerikG:GridViewHeaderCell">
                                                            <Setter Property="Template">
                                                                <Setter.Value>
                                                                    <ControlTemplate TargetType="telerikG:GridViewHeaderCell">
                                                                        <ContentPresenter>
                                                                            <StackPanel Orientation="Horizontal">
                                                                                <TextBlock  Text="{Binding ErrorHeading, TargetNullValue=Errors}"/>
                                                                            
                                                                            </StackPanel>
                                                                        </ContentPresenter>
                                                                    </ControlTemplate>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Style>
                                                     </telerikG:GridViewDataColumn.HeaderCellStyle>
    <telerikG:GridViewDataColumn  Width="Auto" MinWidth="110" IsReadOnly="True">
                                                    <telerikG:GridViewDataColumn.HeaderCellStyle>
                                                        <Style TargetType="telerikG:GridViewHeaderCell">
                                                            <Setter Property="Template">
                                                                <Setter.Value>
                                                                    <ControlTemplate TargetType="telerikG:GridViewHeaderCell">
                                                                        <ContentPresenter>
                                                                            <StackPanel Orientation="Horizontal">
                                                                                <TextBlock  Text="{Binding ErrorHeading, TargetNullValue=Errors}"/>
                                                                            
                                                                            </StackPanel>
                                                                        </ContentPresenter>
                                                                    </ControlTemplate>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Style>
                                                     </telerikG:GridViewDataColumn.HeaderCellStyle>
    <telerikG:GridViewDataColumn  Width="Auto" MinWidth="110" IsReadOnly="True">
                                                    <telerikG:GridViewDataColumn.HeaderCellStyle>
                                                        <Style TargetType="telerikG:GridViewHeaderCell">
                                                            <Setter Property="Template">
                                                                <Setter.Value>
                                                                    <ControlTemplate TargetType="telerikG:GridViewHeaderCell">
                                                                        <ContentPresenter>
                                                                            <StackPanel Orientation="Horizontal">
                                                                                <TextBlock  Text="{Binding ErrorHeading, TargetNullValue=Errors}"/>
                                                                            
                                                                            </StackPanel>
                                                                        </ContentPresenter>
                                                                    </ControlTemplate>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Style>
                                                     </telerikG:GridViewDataColumn.HeaderCellStyle>
    <telerikG:GridViewDataColumn.HeaderCellStyle>
                                                        <Style TargetType="telerikG:GridViewHeaderCell">
                                                            <Setter Property="Template">
                                                                <Setter.Value>
                                                                    <ControlTemplate TargetType="telerikG:GridViewHeaderCell">
                                                                        <ContentPresenter>
                                                                            <StackPanel Orientation="Horizontal">
                                                                                <TextBlock  Text="{Binding ErrorHeading, TargetNullValue=Errors}"/>
                                                                            
                                                                            </StackPanel>
                                                                        </ContentPresenter>
                                                                    </ControlTemplate>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Style>
                                                     </telerikG:GridViewDataColumn.HeaderCellStyle>
    <telerikG:GridViewDataColumn.HeaderCellStyle>
                                                        <Style TargetType="telerikG:GridViewHeaderCell">
                                                            <Setter Property="Template">
                                                                <Setter.Value>
                                                                    <ControlTemplate TargetType="telerikG:GridViewHeaderCell">
                                                                        <ContentPresenter>
                                                                            <StackPanel Orientation="Horizontal">
                                                                                <TextBlock  Text="{Binding ErrorHeading, TargetNullValue=Errors}"/>
                                                                            
                                                                            </StackPanel>
                                                                        </ContentPresenter>
                                                                    </ControlTemplate>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Style>
                                                     </telerikG:GridViewDataColumn.HeaderCellStyle>
    <telerikG:GridViewDataColumn.HeaderCellStyle>
          <Style TargetType="telerikG:GridViewHeaderCell">
                   <Setter Property="Template">
                         <Setter.Value>
                             <ControlTemplate TargetType="telerikG:GridViewHeaderCell">                                                                                           <ContentPresenter>
          <StackPanel Orientation="Horizontal">                                                                          <TextBlock  Text="{Binding ErrorHeading, TargetNullValue=Errors}"/>
            </StackPanel>                                                     </ContentPresenter>
                                                                    </ControlTemplate>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Style>
                                                     </telerikG:GridViewDataColumn.HeaderCellStyle>
  12. Dipti
    Dipti avatar
    2 posts
    Member since:
    Jul 2011

    Posted 02 Aug 2011 Link to this post

    Hi Pavel,

    In your attached code below is code statement,

    <UserControl.Resources>
            <local:Headers x:Key="Headers" />
        </UserControl.Resources>

    Suppose my Headers class is parameter less then it will give me error. Could you please suggest any other way. As i am trying to bind source class as my PresentationModel class.
  13. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 02 Aug 2011 Link to this post

    Hi Dipti,

     

    Generally you do not have to predefine the template of GridViewHeaderCell to achieve the desired result. In this way you will loose its default appearance and capabilities. The better option is to predefine its Header property. Furthermore I believe that the following one would be useful for you on that matter "GridViewCellHeader style unable to see datacontext"


    Hope this helps!


    Kind regards,
    Vanya Pavlova
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  14. Deborah
    Deborah avatar
    31 posts
    Member since:
    Jun 2011

    Posted 30 Aug 2011 Link to this post

    Thank you very very much Pavel,  your sample project has just solved my problem.
Back to Top
DevCraft banner