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

Unable to Bind Trigger on ControlTemplate

4 Answers 197 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pardeep
Top achievements
Rank 1
Pardeep asked on 12 Jan 2016, 08:22 AM

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.

4 Answers, 1 is accepted

Sort by
0
Pardeep
Top achievements
Rank 1
answered on 13 Jan 2016, 05:12 AM
I post this question yesterday, still no reply from Telerik team. Any update guys ?
0
Rosy Topchiyska
Telerik team
answered on 14 Jan 2016, 01:32 PM
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
0
Pardeep
Top achievements
Rank 1
answered on 15 Jan 2016, 10:23 AM

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.

0
Rosy Topchiyska
Telerik team
answered on 20 Jan 2016, 08:45 AM
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
Tags
General Discussions
Asked by
Pardeep
Top achievements
Rank 1
Answers by
Pardeep
Top achievements
Rank 1
Rosy Topchiyska
Telerik team
Share this question
or