Problem with RadTreeView Node localisation updates

4 posts, 0 answers
  1. Paul Whittam
    Paul Whittam avatar
    3 posts
    Member since:
    Oct 2006

    Posted 06 Apr 2011 Link to this post

    Hi,
    I am building an app where the localisation can be changed on the fly, and in one area, have a RadTreeView with conditional Header text on the nodes, set via code-behind:
    RadTreeViewItem childNode = new RadTreeViewItem();
    childNode.Header = doShf == 7 ? ApplicationStrings.HolidayOB : ApplicationStrings.GeneralOB;
    childNode.Header += accountsViewModel.OpeningBalance.ToString();
    childNode.FontWeight = FontWeights.Normal;
    treeNode.Items.Add(childNode);
    The issue comes when I change the localisation setting, in that all other components correctly reflect the localisation change (based on the same implementation of the ApplicationsStrings), however the tree node header text does not (if I change the localisation prior to the page loading, it works ok).

    The xaml is in its simplest form:
    <telerik:RadTreeView x:Name="radAccountsTree" MaxHeight="330" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto">
       <telerik:RadTreeView.ItemTemplate>
          <DataTemplate>
             <TextBlock Text="{Binding Header}"/>
          </DataTemplate>
       </telerik:RadTreeView.ItemTemplate>
    </telerik:RadTreeView>
    I've tried looking through all the Forum threads, but cannot find anything along similar lines.
    Any assistance would be gratefully received.

    Thanks
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 11 Apr 2011 Link to this post

    Hi Paul Whittam,

    Could you please elaborate more on how you change the localization settings from code behind? You can send a support ticket in order to attach a file. We can also change this ticket type to GeneralFeedBack.

    Best wishes,
    Petar Mladenov
    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. Paul Whittam
    Paul Whittam avatar
    3 posts
    Member since:
    Oct 2006

    Posted 12 Apr 2011 Link to this post

    Hi,
    We are changing the localisation using the following code which is on one of the MainPage controls:
    private void cmbLanguage_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo(((RadComboBoxItem)((RadComboBox)sender).SelectedItem).Tag.ToString());
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(((RadComboBoxItem)((RadComboBox)sender).SelectedItem).Tag.ToString());
        ((ResourceWrapper)App.Current.Resources["ResourceWrapper"]).ApplicationStrings = new ApplicationStrings();
    }

    Having looked a bit deeper into the issue, I suspect that the problem is that the Header text that I am dynamically setting is does not have the Binding Source specified, thus when then language is changed on-the-fly, a refresh is not triggered for these particular controls (all controls built in xaml refresh fine).

    The code that builds the controls onto the page is as follows:
    private void accountsService_RetrieveAccountsByVarianceCompleted(object sender, RetrieveAccountsByVarianceCompletedEventArgs e)
    {
        if (e.Result != null)
        {
            foreach (VarianceAccountsViewModel varianceAccounts in e.Result)
            {
                int doShf = varianceAccounts.DO_SHF;
                if (varianceAccounts.RelatedAccounts.Count > 0)
                {
                    foreach (AccountsViewModel accountsViewModel in varianceAccounts.RelatedAccounts)
                    {
                        string resourceString = string.Empty;
                        RadTreeViewItem treeNode = new RadTreeViewItem();
                        treeNode.Header = accountsViewModel.AccountName;
                        treeNode.FontWeight = FontWeights.SemiBold;
                        treeNode.IsExpanded = true;
                        radAccountsTree.Items.Add(treeNode);
                        RadTreeViewItem childNode;
                        childNode = new RadTreeViewItem();
                        childNode.Header = doShf == 7 ? ApplicationStrings.HolidayOB : ApplicationStrings.GeneralOB;
                        childNode.Header += accountsViewModel.OpeningBalance.ToString();
                        childNode.FontWeight = FontWeights.Normal;
                        treeNode.Items.Add(childNode);
                          
                        childNode = new RadTreeViewItem();
                        childNode.Header = doShf == 7 ? ApplicationStrings.HolidayYTD : ApplicationStrings.GeneralYTD;
                        childNode.Header += accountsViewModel.YearToDate.ToString();
                        childNode.FontWeight = FontWeights.Normal;
                        treeNode.Items.Add(childNode);
                          
                        childNode = new RadTreeViewItem();
                        childNode.Header = doShf == 7 ? ApplicationStrings.HolidayPP : ApplicationStrings.GeneralPP;
                        childNode.Header += accountsViewModel.ProjectedPeriod.ToString();
                        childNode.FontWeight = FontWeights.Normal;
                        treeNode.Items.Add(childNode);
                          
                        childNode = new RadTreeViewItem();
                        childNode.Header = doShf == 7 ? ApplicationStrings.HolidayAA : ApplicationStrings.GeneralAA;
                        childNode.Header += "0";
                        childNode.FontWeight = FontWeights.Normal;
                        treeNode.Items.Add(childNode);
                        childNode = new RadTreeViewItem();
                        childNode.Header = doShf == 7 ? ApplicationStrings.HolidayBAL : ApplicationStrings.GeneralBAL;
                        childNode.Header += accountsViewModel.Balance.ToString();
                        childNode.FontWeight = FontWeights.Normal;
                        treeNode.Items.Add(childNode);
                    }
                }
            }
        }
    }
    I have trawled the variious forums to try to ascertain how to set the binding source, but so far have come up with nothing.
    Any assistance gratefully received.

  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 15 Apr 2011 Link to this post

    Hello Paul Whittam,

    The RadTreeView is just a visual representation of your data. Once you have set your RadTreeViewItems headers, they cannot be replaced automatically when changing the current culture. This should be achieved with databinding to Viewmodels. The ViewModels should get their data from the application resources(and possibly updates it/ changes it( "Headername" + 0) and every change in the viewmodel will reflect into the TreeView immediately if you implement the IINotifyPropertyChanged .

    Regards,
    Petar Mladenov
    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
Back to Top