Problem with actual version 2011.3.1116.1040 of Silverlight Tabcontrol

5 posts, 1 answers
  1. Richard Koslik
    Richard Koslik avatar
    71 posts
    Member since:
    Apr 2010

    Posted 19 Dec 2011 Link to this post

    Hello!

    Some days ago I installed the newest version of Silverlight controls and afterwards I changed my TabControl (Microsoft-SDK) to a RadTabControl.

    My situation is now the following:
    I use the RadTabControl for changing between my overview (RadGridView) and the details of the selected data item. I have now a bounded variable for the property "SelectedIndex" of the RadTabControl. If this index changes from 0 to 1, I check in the setter of the binding variable, if the SelectedDataItem is null or not. If it is null then I set my binding variable again to 0.
    My problem is now that I can set the binding variable to 0, but it is not done / not shown ... I am still on the detail page.

    Is this a bug or is there a difference between the normal TabControl and the RadTabControl?

    best Regards,
    Richard Koslik
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 22 Dec 2011 Link to this post

    Hello,

     We managed to reproduce this behavior and it is expected in RadTabControl. In the RadTabControl's logic we have re-insured, that in a "property bound to SelectedIndex" 'setter re-setting this property is not allowed. However, this could be workarounded, for example like so (really bad workaround):

    public int CurrTabIndex
         {
             get { return _currtabIndex; }
             set
             {
                 if (value == 1 && this.CurrEmployee == null)
                 {
                     Application.Current.RootVisual.Dispatcher.BeginInvoke(() =>
                         {
                             CurrTabIndex = 0;
                         });
                      
                     return;
                 }
                 _currtabIndex = value;
                 this.OnPropertyChanged("CurrTabIndex");
             }
         }
     However, we suggest you use the PreviewSelectionChanged event or another MVVM approach - you can bind the IsEnabled of the RadTabItem to the CyrrentItem property of that is bound to the Currentitem of the GridView like so:
    <telerik:RadTabControl x:Name="tabControl" SelectedIndex="{Binding CurrTabIndex, Mode=TwoWay}">
            <telerik:RadTabItem Header="MainTab">
                <telerik:RadGridView ItemsSource="{Binding Employees}" SelectedItem="{Binding CurrEmployee, Mode=TwoWay}"/>
            </telerik:RadTabItem>
     
            <telerik:RadTabItem Header="Info Tab" IsEnabled="{Binding Path=CurrEmployee, Converter={StaticResource converter} }">
    public class SampleConverter: IValueConverter
       {
           public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
           {
               if (value == null)
               {
                   return false;
               }
               return true;
           }
    You can find the last approach realized in the attached solution. Kind regards,
    Petar Mladenov
    the Telerik team

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

  3. DevCraft banner
  4. Richard Koslik
    Richard Koslik avatar
    71 posts
    Member since:
    Apr 2010

    Posted 10 Jan 2012 Link to this post

    Hello,

    thanks for your help. I tried it now with the "PreviewSelectionChanged"-Event and it works fine, but I have one problem.

    I have a RadTabControl with two tabitems. On the second tabitem I have also placed a RadTabControl (Child). If I change now the SelectedIndex of the second RadTabControl (Child) the "PreviewSelectionChanged"-Event of the main-Tabcontrol is also executed, WHY??

    I bound the Event like this, I also tried it in code-behind, but it is always the same problem:
    <telerik:RadTabControl x:Name="tabControl1" SelectedIndex="{Binding iTabIndex,Mode=TwoWay}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="PreviewSelectionChanged">
                        <cmd:EventToCommand Command="{Binding evPreviewSelChangedTC, Mode=OneWay}" PassEventArgsToCommand="True" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>

    Is this a bug or something else?


    regards,
    Richard Koslik



  5. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 12 Jan 2012 Link to this post

    Hi,

    PreviewSelectionChanged and SelectionChanged events are routed events which means they bubble up the visual tree. Thus you can hear them in the parent TabControl when they are fired by the inner TabControl.

    All the best,
    Hristo
    the Telerik team

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

  6. Richard Koslik
    Richard Koslik avatar
    71 posts
    Member since:
    Apr 2010

    Posted 17 Jan 2012 Link to this post

    Ok, thanks for the information.


    best regards

    Richard Koslik
Back to Top
DevCraft banner