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

Cannot pass RadWindow object as command parameter

4 Answers 395 Views
Window
This is a migrated thread and some comments may be shown as answers.
Joachim
Top achievements
Rank 1
Joachim asked on 11 Jun 2018, 07:23 AM

Hi,

I'm trying to pass the window object of a window type RadWindow as command parameter to the code behind - however not RadWindow will be passed, but some helper windows classes of type WindowHostWindow.

The XML look like this:

<telerik:RadRibbonButton Text="Speichern"
                                             AllowDrop="True"
                                             LargeImage="..\Images\save.png"
                                             Size="Large"
                                             telerik:ScreenTip.Title="Speichern"
                                             telerik:ScreenTip.Description="Einen neuen Task anlegen."
                                             telerik:KeyTipService.AccessText="S"
                                             IsEnabled="{Binding CanSave}"
                                             Command="{Binding SaveCommand}"
                                             CommandParameter="{x:Reference Name=taskwindow}"
                                             IsDefault="True"/>

 

The Code behind(implementation of the command):

private void SaveProcess(object obj)
{

...

RadWindow wnd = (RadWindow)obj; <= this cast already fails as some helper class will be passed instaed of the expected RadWindow

 

Using the "normal" Window class instaed of the Telerik one, the code runs without any issues.

 

Looking forward to your answer.

 

Thanks,

Joachim

 

 

 

4 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 14 Jun 2018, 07:16 AM
Hello Joachim,

Thank you for your interest in our RadWindow control.

I have tested your scenario but wasn't able to reproduce it on my side. I am not familiar with your implementation set-up but I am assuming that you have placed RadRibbonView control inside RadWindow as a MainWindow. Attached to this reply is the sample project which I used to test your scenario based on the provided code snippet. In the command executed method of the SaveCommand, the parameter is the RadWindow. Can you take a look at this project and let me know what I am missing in order to reproduce this behavior my side.

Looking forward to your reply.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Joachim
Top achievements
Rank 1
answered on 15 Jun 2018, 04:50 AM

Hello Dinko,

thank for your reply. Unfortunatelly your assumption is not fully true. The windows is used as a kind of popup for creating a new data entry (like new email).
Following shows the structure of the window. The command is part of the data context in the back:

<telerik:RadWindow x:Class="Badenia.MDM.UserInterface.Views.NewCI"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        Style="{DynamicResource RadWindowStyle}"
        mc:Ignorable="d"
        Header="Neues Configurations Item" Height="400" Width="928.721" ResizeMode="NoResize" WindowStartupLocation="CenterOwner">
    <telerik:RadWindow.DataContext>
        <localdata:CIBase />
    </telerik:RadWindow.DataContext>
    <telerik:RadWindow.Resources>
        <converter:CITypeIdToVisibilityConverter x:Key="CITypeIdToVisibilityConverter" />
        <converter:IdToADGroupMemberTypeConverter x:Key="IdToADGroupMemberTypeConverter" />
        <converter:SCCM2HiDataConverter x:Key="SCCM2HiDataConverter" />
        <converter:ADDataConverter x:Key="ADDataConverter" />
    </telerik:RadWindow.Resources>
    <Grid>
        <Grid Margin="9">
            <Grid.RowDefinitions>
                <RowDefinition Height="60" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <telerik:RadRibbonGroup Header="Bearbeiten" Visibility="Visible" HorizontalAlignment="Left">
                <telerik:RadCollapsiblePanel >
                    <telerik:RadRibbonButton Text="Speichern"
                                             AllowDrop="True"
                                             LargeImage="..\Images\save.png"
                                             Size="Large"
                                             telerik:ScreenTip.Title="Speichern"
                                             telerik:ScreenTip.Description="Ein neues Configuration Item anlegen."
                                             telerik:KeyTipService.AccessText="S"
                                             IsEnabled="{Binding CanSave}"
                                             Command="{Binding SaveCommand}"
                                             CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                                             IsDefault="True"/>
                    
                    <telerik:RadRibbonButton Text="Abbrechen"
                                             AllowDrop="True"
                                             LargeImage="..\Images\cancel.png"
                                             Size="Large"
                                             telerik:ScreenTip.Title="Vorgang abbrechen"
                                             telerik:ScreenTip.Description="Den Vorgang abbrechen und die Daten verwerfen"
                                             telerik:KeyTipService.AccessText="E"
                                             Command="{Binding CancelCommand}"
                                             CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                                             IsCancel="True"/>
                </telerik:RadCollapsiblePanel>
            </telerik:RadRibbonGroup>            
            <Grid.RowDefinitions>
                <RowDefinition Height="0" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="10" />
                <ColumnDefinition Width="200" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="2" />
            </Grid.ColumnDefinitions>
            
            <!-- Display CI attributes -->
            <telerik:Label Content="Type:" HorizontalAlignment="Left"  VerticalAlignment="Top" Grid.Row="1"/>
            <telerik:Label  Content="Name:" HorizontalAlignment="Left"  VerticalAlignment="Top" Grid.Row="2"/>
            <telerik:Label  Content="Beschreibung:" HorizontalAlignment="Left"  VerticalAlignment="Top" Grid.Row="2" Grid.Column="3"/>
            <telerik:Label  Content="Technischer Owner:" HorizontalAlignment="Left"  VerticalAlignment="Top" Grid.Row="3"/>
            <telerik:Label  Content="Fachlicher Owner:" HorizontalAlignment="Left"  VerticalAlignment="Top" Grid.Row="3" Grid.Column="3"/>
            <telerik:Label  Content="Lizenz:" HorizontalAlignment="Left"  VerticalAlignment="Top" Grid.Row="4"/>
            <telerik:Label  Content="Datenschutzklasse:" HorizontalAlignment="Left"  VerticalAlignment="Top" Grid.Row="4" Grid.Column="3"/>
            <telerik:Label  Content="Gruppe:" HorizontalAlignment="Left"  VerticalAlignment="Top" Grid.Row="5"/>

            <telerik:RadComboBox Grid.Row="1" Grid.Column="1" DisplayMemberPath="Name" SelectedValuePath="Id" SelectedValue="{Binding TypeId}" ItemsSource="{Binding Source={x:Static da:StaticLists.CITypes}, Mode=OneWay}" />
            <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Name}" />
            <TextBox Grid.Row="2" Grid.Column="4" Text="{Binding Description}" />

                <telerik:RadComboBox Grid.Row="3" Grid.Column="1" HorizontalContentAlignment="Left" DropDownWidth="200" DisplayMemberPath="Name" ItemsSource="{Binding UserAccounts}" SelectedValue="{Binding TechnicalOwner}" IsEnabled="{Binding SelectedCI.IsInEditMode}" >
                    <telerik:RadComboBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel />
                        </ItemsPanelTemplate>
                    </telerik:RadComboBox.ItemsPanel>
                </telerik:RadComboBox>
                <telerik:RadComboBox Grid.Row="3" Grid.Column="4" HorizontalContentAlignment="Left" DropDownWidth="200" DisplayMemberPath="Name" ItemsSource="{Binding UserAccounts}" SelectedValue="{Binding BusinessOwner}" IsEnabled="{Binding SelectedCI.IsInEditMode}" >
                    <telerik:RadComboBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel />
                        </ItemsPanelTemplate>
                    </telerik:RadComboBox.ItemsPanel>
                </telerik:RadComboBox>
                <telerik:RadComboBox Grid.Row="4" Grid.Column="1" HorizontalContentAlignment="Left" DropDownWidth="200" DisplayMemberPath="Name" ItemsSource="{Binding Licences }" SelectedValue="{Binding Licence}" IsEnabled="{Binding SelectedCI.IsInEditMode}" >
                    <telerik:RadComboBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel />
                        </ItemsPanelTemplate>
                    </telerik:RadComboBox.ItemsPanel>
                </telerik:RadComboBox>


                <telerik:RadComboBox Grid.Row="4" Grid.Column="4" HorizontalContentAlignment="Left" VerticalAlignment="Center" DropDownWidth="200" DisplayMemberPath="DisplayName" ItemsSource="{Binding Source={x:Static da:StaticLists.ListOfDataProtectionClasses}, Mode=OneWay}"  SelectedValuePath="Id" SelectedValue="{Binding DataProtectionClassId}" IsEnabled="{Binding SelectedCI.IsInEditMode}" />


                <StackPanel Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="1" Grid.RowSpan="4" HorizontalAlignment="Stretch" >
                <telerik:RadDropDownButton HorizontalContentAlignment="Left" DropDownWidth="300" IsOpen="{Binding IsCIGroupOpen, Mode=TwoWay}"  Content="{Binding ConfigurationItemGroup.Name, FallbackValue='Bitte ein Element auswählen', Mode=TwoWay}" >
                    <telerik:RadDropDownButton.DropDownContent>
                        <telerik:RadTreeView Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Grid.RowSpan="4" x:Name="TreeView" MouseDoubleClick="TreeView_MouseDoubleClick" ItemsSource="{Binding CIGroups, Mode=OneTime}" SelectedItem="{Binding ConfigurationItemGroup, Mode=TwoWay}" ItemTemplate="{StaticResource CIGroupL0}"/>
                    </telerik:RadDropDownButton.DropDownContent>
                </telerik:RadDropDownButton>
            </StackPanel>

            <!-- AD specific grid -->
            <Grid Name="ADGrid" Grid.Row="7" Grid.ColumnSpan="5" Grid.RowSpan="2" Visibility="{Binding TypeId, Mode=TwoWay, Converter={StaticResource CITypeIdToVisibilityConverter}, ConverterParameter=1}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="2" />
                </Grid.ColumnDefinitions>

                <telerik:Label  Content="Type der Mitgliedschaft:" HorizontalAlignment="Left"  VerticalAlignment="Top" />
                <telerik:Label  Content="AD Gruppe:" HorizontalAlignment="Left"  VerticalAlignment="Top" Grid.Row="1"/>

                <telerik:RadComboBox Grid.Column="1" DisplayMemberPath="DisplayName" SelectedValuePath="Id" SelectedValue="{Binding MembershipType, Converter={StaticResource IdToADGroupMemberTypeConverter}}" ItemsSource="{Binding Source={x:Static da:StaticLists.ListOfGroupMemberTypes}, Mode=OneWay}" />
                <StackPanel HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="4" >
                    <telerik:RadDropDownButton HorizontalContentAlignment="Left" DropDownWidth="600"  IsOpen="{Binding IsDropDownOpenedAD, Mode=TwoWay}" Content="{Binding CN, FallbackValue='Bitte eine Gruppe auswählen', Mode=TwoWay}" >
                        <telerik:RadDropDownButton.DropDownContent>
                            <telerik:RadTreeView Name="TreeViewAD" IsSingleExpandPath="True" ItemDoubleClick="TreeView_ItemDoubleClick" VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.IsDeferredScrollingEnabled="True" Grid.Column="1" Grid.ColumnSpan="2" ItemsSource="{Binding ADEntries, Mode=OneTime}"  SelectedItem="{Binding ADGroup, Mode=TwoWay, Converter={StaticResource ADDataConverter}}" ItemTemplate="{StaticResource ADGroupL0}" ItemContainerStyle="{StaticResource AdTreeViewStyle}" />
                        </telerik:RadDropDownButton.DropDownContent>
                    </telerik:RadDropDownButton>
                </StackPanel>
            </Grid>

            <!-- SCCM specific grid -->
            <Grid Name="SccmGrid" Grid.Row="7" Grid.ColumnSpan="5" Grid.RowSpan="2" Visibility="{Binding TypeId, Mode=TwoWay, Converter={StaticResource CITypeIdToVisibilityConverter}, ConverterParameter=2}" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="2" />
                </Grid.ColumnDefinitions>

                <telerik:Label  Content="SCCM Collection Gruppe:" HorizontalAlignment="Left"  VerticalAlignment="Top"/>
                <StackPanel HorizontalAlignment="Stretch" Grid.Column="1" Grid.ColumnSpan="4" >
                    <telerik:RadDropDownButton HorizontalContentAlignment="Left" IsOpen="{Binding IsDropDownOpenedSCCM, Mode=TwoWay}" DropDownWidth="600" Content="{Binding SCCMCollection.Name, FallbackValue='Bitte eine Collection auswählen', Mode=OneWay}" >
                        <telerik:RadDropDownButton.DropDownContent>
                            <telerik:RadTreeView Name="TreeViewSCCM" VirtualizingStackPanel.IsVirtualizing="True" ItemDoubleClick="TreeView_ItemDoubleClick" ScrollViewer.IsDeferredScrollingEnabled="True" Grid.Column="1" Grid.ColumnSpan="2" ItemsSource="{Binding SccmEntries, Mode=OneTime}" SelectedItem="{Binding SCCMCollection, Mode=TwoWay, Converter={StaticResource SCCM2HiDataConverter}}" ItemTemplate="{StaticResource SCCMGroupL0}" />
                        </telerik:RadDropDownButton.DropDownContent>
                    </telerik:RadDropDownButton>
                </StackPanel>
            </Grid>
            </Grid>
        </Grid>
    </Grid>
</telerik:RadWindow>

Hope this full sample gives you the necessary hints for reproducing the issue.

Thanks,
Joachim

0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 19 Jun 2018, 02:33 PM
Hi Joachim,

Thank you for the provided code snippet. 

I manage to reproduce this helper class which comes as a parameter. Basically, CommandParameter is bind to a parent of type Window using RelativeSource. To get the RadWindow you can set the AncestorType to be {x:Type telerik:RadWindow}. I have modified my project to demonstrate this approach. Give it a try and let me know if it works on your side. 

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Joachim
Top achievements
Rank 1
answered on 02 Jul 2018, 10:43 AM

Hi Dinko,

thanks for the updated example, which solved my problem!

Have a good day and take care,

Joachim

Tags
Window
Asked by
Joachim
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Joachim
Top achievements
Rank 1
Share this question
or