Bindingerrors with commands in ContextualTab

4 posts, 1 answers
  1. Mike
    Mike avatar
    38 posts
    Member since:
    May 2011

    Posted 06 Sep 2011 Link to this post

    Hello,

    I have a a RibbonView hosted in my MainWiindow. All the RibbonTabs (and the ContextualTabs) are defined in the MainWindow.xaml. The second part in the MainWindow is a RadTabControl that is used for showing all ViewModels (and the corresponding Views).
    Every UserControl in the RadTabControl has a corresponding ContextualRibbonTab. The Command of the RibbonButtons inside the ContextualTabs are bound to commands in the SelectedItem of the RadTabControl (Commands defined in the ViewModel). Everything works fine, the only problem is, that everytime a new Tab get's loaded in the RadTabControl, WPF tries to bind all the Commands of all ContextualTabs to the currently SelectedItem in the RadTabControl, which causes a lot of binding errors for those commands that don't exist in the currentyl active viewmodel. Is there a way to prevent WPF from rebinding alle the commands, i all want to bind the Commands of the corresponding ContextualTab.

    Here is the definition of my RibbonTabs:
    <!--Kontext Tab's-->
                <telerik:RadRibbonView.ContextualGroups>
                    <telerik:RadRibbonContextualGroup  x:Name="uxContextualGroupCustomerOverview"
                                                           Header="Kunden"
                                                           Color="Goldenrod">
                        <telerik:RadRibbonContextualGroup.Style>
                            <Style TargetType="telerik:RadRibbonContextualGroup">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding WorkspaceView.CurrentItem.ContextualTabGroup}" Value="Kundenübersicht">
                                        <Setter Property="IsActive" Value="True"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </telerik:RadRibbonContextualGroup.Style>
                    </telerik:RadRibbonContextualGroup>
                    <telerik:RadRibbonContextualGroup  x:Name="uxContextualGroupEvents"
                                                           Header="Veranstaltungen"
                                                           Color="Orchid">
                        <telerik:RadRibbonContextualGroup.Style>
                            <Style TargetType="telerik:RadRibbonContextualGroup">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding WorkspaceView.CurrentItem.ContextualTabGroup}" Value="Veranstaltungsübersicht">
                                        <Setter Property="IsActive" Value="True"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </telerik:RadRibbonContextualGroup.Style>
                    </telerik:RadRibbonContextualGroup>
                    <telerik:RadRibbonContextualGroup  x:Name="uxContextualGroupEmployeeOverView"
                                                           Header="Mitarbeiter"
                                                           Color="IndianRed">
                        <telerik:RadRibbonContextualGroup.Style>
                            <Style TargetType="telerik:RadRibbonContextualGroup">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding WorkspaceView.CurrentItem.ContextualTabGroup}" Value="Mitarbeiterübersicht">
                                        <Setter Property="IsActive" Value="True"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </telerik:RadRibbonContextualGroup.Style>
                    </telerik:RadRibbonContextualGroup>
                    <telerik:RadRibbonContextualGroup  x:Name="uxContextualGroupReport"
                                                               Header="Report"
                                                               Color="ForestGreen">
                        <telerik:RadRibbonContextualGroup.Style>
                            <Style TargetType="telerik:RadRibbonContextualGroup">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding WorkspaceView.CurrentItem.ContextualTabGroup}" Value="Bericht">
                                        <Setter Property="IsActive" Value="True"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </telerik:RadRibbonContextualGroup.Style>
                    </telerik:RadRibbonContextualGroup>
                    <telerik:RadRibbonContextualGroup  x:Name="uxContextualGroupMap"
                                                                   Header="Karte"
                                                                   Color="DarkRed">
                        <telerik:RadRibbonContextualGroup.Style>
                            <Style TargetType="telerik:RadRibbonContextualGroup">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding WorkspaceView.CurrentItem.ContextualTabGroup}" Value="Karte">
                                        <Setter Property="IsActive" Value="True"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </telerik:RadRibbonContextualGroup.Style>
                    </telerik:RadRibbonContextualGroup>
                    <telerik:RadRibbonContextualGroup  x:Name="uxContextualGroupEventRegistrationOverView"
                                                                   Header="Veranstaltungsanmeldungen"
                                                                   Color="LightSalmon">
                        <telerik:RadRibbonContextualGroup.Style>
                            <Style TargetType="telerik:RadRibbonContextualGroup">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding WorkspaceView.CurrentItem.ContextualTabGroup}" Value="Veranstaltungsanmeldungsübersicht">
                                        <Setter Property="IsActive" Value="True"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </telerik:RadRibbonContextualGroup.Style>
                    </telerik:RadRibbonContextualGroup>
                </telerik:RadRibbonView.ContextualGroups>
     
                <!--Tabs-->
                <telerik:RadRibbonTab Header="Start">
                    <telerik:RadRibbonGroup Header="Gehe zu">
                        <telerik:RadRibbonButton Text="Start" Command="{Binding Path=ShowWorkspaceCommand}" CommandParameter="StartViewModel" LargeImage="/SigiNX;component/Images/32/sigi.png" Size="Large" />
                        <telerik:RadRibbonButton Text="Kunden" Command="{Binding Path=ShowWorkspaceCommand}" CommandParameter="CustomerOverViewModel" LargeImage="/SigiNX;component/Images/32/customer.png" Size="Large" />
                        <telerik:RadRibbonButton Text="Mitarbeiter" Command="{Binding Path=ShowWorkspaceCommand}" CommandParameter="EmployeeOverViewModel" LargeImage="/SigiNX;component/Images/32/employee.png" Size="Large"/>
                        <telerik:RadRibbonButton Text="Veranstaltungs termine" Command="{Binding Path=ShowWorkspaceCommand}" CommandParameter="EventDateOverViewModel" LargeImage="/SigiNX;component/Images/32/event_date.png" Size="Large"/>
                        <telerik:RadRibbonButton Text="Veranstaltungs anmeldungen" Command="{Binding Path=ShowWorkspaceCommand}" CommandParameter="EventRegistrationOverViewModel" LargeImage="/SigiNX;component/Images/32/event_registration.png" Size="Large"/>
                        <telerik:RadRibbonButton Text="Karte" Command="{Binding Path=ShowWorkspaceCommand}" CommandParameter="MapViewModel" LargeImage="/SigiNX;component/Images/32/map.png" Size="Large"/>
                   </telerik:RadRibbonGroup>
                </telerik:RadRibbonTab>
     
                <telerik:RadRibbonTab Header="Anzeige" ContextualGroupName="uxContextualGroupCustomerOverview">
                    <telerik:RadRibbonGroup Header="Bearbeiten">
                            <telerik:RadRibbonSplitButton Text="Neu" Size="Large" LargeImage="/SigiNX;component/Images/32/customer_new.png"
                                                      Command="{Binding WorkspaceView.CurrentItem.CreateCommand}" CommandParameter="CustomerDetailViewModel"  DropDownButtonPosition="Bottom" DropDownIndicatorVisibility="Visible">
                            <telerik:RadRibbonSplitButton.DropDownContent>
                               <telerik:RadContextMenu BorderThickness="0">
                                    <telerik:RadMenuItem Header="neuer Mitarbeiter" Command="{Binding WorkspaceView.CurrentItem.CreateCommand}" CommandParameter="EmployeeDetailViewModel">
                                        <telerik:RadMenuItem.Icon>
                                            <Image Source="/SigiNX;component/Images/16/employee_new.png" />
                                        </telerik:RadMenuItem.Icon>
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Header="neuer Vertrag" Command="{Binding WorkspaceView.CurrentItem.CreateCommand}" CommandParameter="">
                                        <telerik:RadMenuItem.Icon>
                                            <Image Source="/SigiNX;component/Images/16/contract_new.png" />
                                        </telerik:RadMenuItem.Icon>
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Header="neue Zustimmungserklärung" Command="{Binding WorkspaceView.CurrentItem.CreateCommand}" CommandParameter="">
                                        <telerik:RadMenuItem.Icon>
                                            <Image Source="/SigiNX;component/Images/16/sign_new.png" />
                                        </telerik:RadMenuItem.Icon>
                                    </telerik:RadMenuItem>
                                </telerik:RadContextMenu>
                            </telerik:RadRibbonSplitButton.DropDownContent>
                        </telerik:RadRibbonSplitButton>
                        <StackPanel>
                            <telerik:RadRibbonButton Text="Bearbeiten" Command="{Binding WorkspaceView.CurrentItem.EditCommand}" Size="Medium" SmallImage="/SigiNX;component/Images/16/edit.png"/>
                        </StackPanel>
                    </telerik:RadRibbonGroup>
                    <telerik:RadRibbonGroup Header="Anzeige">
                        <telerik:RadRibbonSplitButton Text="gruppiern" DropDownButtonPosition="Bottom" Size="Large" LargeImage="/SigiNX;component/Images/32/group_by.png">
                            <telerik:RadSplitButton.DropDownContent>
                                <telerik:RadContextMenu BorderThickness="0">
                                    <telerik:RadMenuItem Header="nach Typ" Command="{Binding WorkspaceView.CurrentItem.GroupCommand}" CommandParameter="Typ">
                                        <telerik:RadMenuItem.Icon>
                                            <Image Source="/SigiNX;component/Images/16/employee.png" />
                                        </telerik:RadMenuItem.Icon>
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Header="nach Bezirk" Command="{Binding WorkspaceView.CurrentItem.GroupCommand}" CommandParameter="Bezirk">
                                        <telerik:RadMenuItem.Icon>
                                            <Image Source="/SigiNX;component/Images/16/contract.png" />
                                        </telerik:RadMenuItem.Icon>
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Header="nach Zone" Command="{Binding WorkspaceView.CurrentItem.GroupCommand}" CommandParameter="Zone">
                                        <telerik:RadMenuItem.Icon>
                                            <Image Source="/SigiNX;component/Images/16/trainer.png" />
                                        </telerik:RadMenuItem.Icon>
                                    </telerik:RadMenuItem>
                                </telerik:RadContextMenu>
                            </telerik:RadSplitButton.DropDownContent>
                        </telerik:RadRibbonSplitButton>
                        <telerik:RadRibbonButton Text="Bericht" Command="{Binding WorkspaceView.CurrentItem.ShowReportCommand}" CommandParameter=".\\Reports\\Kundenbericht.mrt"  Size="Large" SmallImage="/SigiNX;component/Images/32/report.png"/>
                    </telerik:RadRibbonGroup>
                    <telerik:RadRibbonGroup Header="Gehe zu">
                        <telerik:RadRibbonButton Text="Mitarbeiter" Command="{Binding WorkspaceView.CurrentItem.ShowFilteredWorkspaceCommand}" CommandParameter="EmployeeOverView" Size="Large" LargeImage="/SigiNX;component/Images/32/employee.png" />
                        <StackPanel>
                            <telerik:RadRibbonButton Text="Karte" Command="{Binding WorkspaceView.CurrentItem.ShowFilteredWorkspaceCommand}" CommandParameter="MapView" Size="Medium" SmallImage="/SigiNX;component/Images/16/map.png" />
                            <telerik:RadRibbonButton Text="Verträge" Size="Medium" SmallImage="/SigiNX;component/Images/16/contract.png" />
                            <telerik:RadRibbonButton Text="Produkte" Size="Medium" SmallImage="/SigiNX;component/Images/16/product.png" />
                        </StackPanel>
                        <StackPanel>
                            <telerik:RadRibbonButton Text="Konto" Size="Medium" SmallImage="/SigiNX;component/Images/16/accounting.png" />
                            <telerik:RadRibbonButton Text="Veranstaltungen" Command="{Binding WorkspaceView.CurrentItem.ShowFilteredWorkspaceCommand}" CommandParameter="EventDateOverView" Size="Medium" SmallImage="/SigiNX;component/Images/16/event_date.png" />
                            <telerik:RadRibbonButton Text="Zustimmungen" Size="Medium" SmallImage="/SigiNX;component/Images/16/sign.png" />
                        </StackPanel>
                    </telerik:RadRibbonGroup>
                </telerik:RadRibbonTab>
                <telerik:RadRibbonTab Header="Berichte" ContextualGroupName="uxContextualGroupCustomerOverview">
                </telerik:RadRibbonTab>
    ...

  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 06 Sep 2011 Link to this post

    Hello Michael,

    Can you try setting the RadTabControl.IsContentPreseved property to True and let me know if this fixes the issue?

    Best wishes,
    Tina Stancheva
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Mike
    Mike avatar
    38 posts
    Member since:
    May 2011

    Posted 06 Sep 2011 Link to this post

    Thanks for the quick response, but unfortunately that didn't solve my problem. WPF still tries to bind all the commands to the selecteditem of the tabcontrol.
    An example: I have 4 contextual tab's (CT1, CT2, CT3, CT4) and 4 different viewmodels (VM1, VM2, VM3, VM4). VM1 corresponds with CT1 and so on... 
    Each viewmodel has different commands that are bound in the corresponding contextual tab. The viewmodels are displayed in the tabControl, but they are loaded dynamic. so not all viewmodels are loaded at the same time. When the application loads, only VM1 is loaded in a tab, and now WPF tries to bind not only the commands of CT1, but also of CT2, CT3 and CT4 - and this of course causes some binding errors.
    i tried to set the visibillity  of the all contextual  tab's to collapsed, and only show the one corresponding to the vm, but that ended in an exception thrown by the ribbonview. i can't find a way to prevent the binding of all commands? do you have an idea?

    By the way, your suggestion with IsContentPreserved made my tab-switching a lot faster, i will keep that one - thanks a lot :-)
  5. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 08 Sep 2011 Link to this post

    Hello Michael,

    It seems your issue is caused by this bug introduced in the RadRibbonView. We are currently working on a fix so please track the PITS item for more details.

    Best wishes,
    Tina Stancheva
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top