Unable to Bind Trigger on ControlTemplate

5 posts, 0 answers
  1. Pardeep
    Pardeep avatar
    7 posts
    Member since:
    Jan 2016

    Posted 12 Jan Link to this post

    Hi,

     We are trying to bind Trigger on Stackpanel loaded while using RadMessageBox control. Example :

         <!-- CustomMessageBox Template -->
                <ControlTemplate x:Key="MessageBoxTemplate" TargetType="messageBox:RadMessageBoxControl">
                    <Border Padding="12" Background="{StaticResource PhoneChromeBrush}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>

                            <ContentControl x:Name="PART_Title" Grid.Row="0"
                                        HorizontalContentAlignment="Left"
                                        FontSize="{StaticResource PhoneFontSizeLarge}"
                                        FontFamily="{StaticResource PhoneFontFamilySemiBold}"
                                        Margin="{StaticResource PhoneMargin}"/>

                            <ContentControl HorizontalContentAlignment="Left" Grid.Row="1"
                                            VerticalContentAlignment="Top" Margin="{StaticResource PhoneMargin}"
                                            x:Name="PART_Message"/>

                            <CheckBox x:Name="PART_CheckBox" Grid.Row="2"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Bottom"/>

                            <ContentControl x:Name="PART_ButtonsContainer" Grid.Row="3"
                                        HorizontalContentAlignment="Stretch" Margin="12,0" Width="440">
                                <ContentControl.ContentTemplate>
                                    <DataTemplate>
                                        <StackPanel x:Name="PART_ButtonsPanel"
                                                Orientation="Vertical" HorizontalAlignment="Stretch">
                                                <i:Interaction.Triggers>
                                                    <i:EventTrigger EventName="Loaded">
                                                    <i:InvokeCommandAction Command="{Binding DataContext.CustomMessageBoxStackPanelLoadedCommand}" CommandParameter="{Binding PART_ButtonsPanel}"/>
                                                    </i:EventTrigger>
                                                </i:Interaction.Triggers>
                                        </StackPanel>
                                    </DataTemplate>
                                </ContentControl.ContentTemplate>
                            </ContentControl>

                        </Grid>
                    </Border>
                </ControlTemplate>

    We are unable to Trigger stackpanel loaded event. Code behind file :

    private bool _CustomMessageBoxStackPanelLoadedCommandCanExecute = true;

            bool CustomMessageBoxStackPanelLoadedCommandCanExecute
            {
                get
                {
                    return _CustomMessageBoxStackPanelLoadedCommandCanExecute;
                }

                set
                {
                    if (_CustomMessageBoxStackPanelLoadedCommandCanExecute == value)
                    {
                        return;
                    }

                    _CustomMessageBoxStackPanelLoadedCommandCanExecute = value;

                    RaisePropertyChanged("CustomMessageBoxStackPanelLoadedCommandCanExecute");

                    if (_CustomMessageBoxStackPanelLoadedCommand != null)
                        _CustomMessageBoxStackPanelLoadedCommand.RaiseCanExecuteChanged();
                }
            }

            private RelayCommand<string> _CustomMessageBoxStackPanelLoadedCommand;

            public ICommand CustomMessageBoxStackPanelLoadedCommand
            {
                get
                {
                    if (_CustomMessageBoxStackPanelLoadedCommand == null)
                    {
                        _CustomMessageBoxStackPanelLoadedCommand = new RelayCommand<string>(CustomMessageBoxStackPanelLoaded, (data) => CustomMessageBoxStackPanelLoadedCommandCanExecute);
                    }

                    return _CustomMessageBoxStackPanelLoadedCommand;
                }
            }

            private void CustomMessageBoxStackPanelLoaded(object obj)
            {
                System.Diagnostics.Debug.WriteLine("Hello");
            }

     

    Please see..

     

    Thanks.

  2. Pardeep
    Pardeep avatar
    7 posts
    Member since:
    Jan 2016

    Posted 12 Jan in reply to Pardeep Link to this post

    I post this question yesterday, still no reply from Telerik team. Any update guys ?
  3. DevCraft banner
  4. Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    551 posts

    Posted 14 Jan Link to this post

    Hi Pardeep,

    Thank you for contacting us.

    RadMessageBox does not support data context. You can either use a static resource for the command:
    <i:InvokeCommandAction Command="{StaticResource Command}" CommandParameter="{Binding ElementName=PART_ButtonsPanel}"/>
    or set a DataContext of the StackPanel, which also should be static resource:
    <StackPanel x:Name="PART_ButtonsPanel" Orientation="Horizontal"  DataContext="{StaticResource ViewModel}">

    Also, please note that the CommandParameter is not set correctly in your example.

    I hope this helps. Let us know if you have any other questions.

    Regards,
    Rosy Topchiyska
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  5. Pardeep
    Pardeep avatar
    7 posts
    Member since:
    Jan 2016

    Posted 15 Jan in reply to Rosy Topchiyska Link to this post

    Hi Rosy,

    I am trying to use ist option you provided. Even I'd skip CommamdParameter option for a moment, your suggestion to use by Command= {StaticResource Command} is not working. (Throwing exception like Failed to load component).

    Thanks.

  6. Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    551 posts

    Posted 20 Jan Link to this post

    Hello Pardeep,

    I have attached a sample project that can help you with this scenario. Please, take a look and let us know if you have any questions.

    Regards,
    Rosy Topchiyska
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner