User Defined constructor with ViewModel injected not firing when using RadTransitionControl

4 posts, 0 answers
  1. Jinish
    Jinish avatar
    3 posts
    Member since:
    Feb 2011

    Posted 02 Nov 2011 Link to this post

    Hello,

    I am having some trouble while using the RadTransition control. The way i am using it is below:

    <UserControl.Resources>
           <Style x:Key="TransitionFrameStyle"
                   TargetType="sdk:Frame">
                <Setter Property="Background"
                        Value="Transparent" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="sdk:Frame">
                            <Border CornerRadius="5">
                                <Grid Background="{TemplateBinding Background}">
                                    <telerik:RadTransitionControl x:Name="PART_FrameCP"
                                                                  Content="{TemplateBinding Content}"
                                                                  ContentTemplate="{TemplateBinding ContentTemplate}">
                                        <telerik:RadTransitionControl.Transition>
                                            <TransitionEffects:SlideAndZoomTransition MinAlpha="0.1"
                                                                                      MinZoom="0.9"
                                                                                      SlideDirection="LeftToRight"
                                                                                      StartSlideAt="0.25" />
                                        </telerik:RadTransitionControl.Transition>
                                    </telerik:RadTransitionControl>
                                    <Border BorderBrush="{TemplateBinding BorderBrush}"
                                            BorderThickness="{TemplateBinding BorderThickness}"
                                            Padding="{TemplateBinding Padding}" />
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    </UserControl.Resources>

    Then using a frame control as below on the page:
    <sdk:Frame Style="{StaticResource TransitionFrameStyle}"
                               Grid.Row="1"
                               NavigationFailed="Frame_NavigationFailed"
                               Source="{Binding Path=SelectedPage.PageUri}" />

    Then in the Viewmodel for this page:
    private readonly ObservableCollection<FramePage> pages;
     
    public UserManagementSummaryViewModel(IRegionManager regionManager)
            {
                if (regionManager == null)
                {
                    throw new ArgumentNullException("regionManager");
                }
     
                this.regionManager = regionManager;
                this.BackCommand = new DelegateCommand(this.NavigateToMainScreen);
                this.RefreshCommand = new DelegateCommand(this.RefreshUserPanel);
                this.ShowIconViewCommand = new DelegateCommand(this.ShowIconView);
                this.ShowListViewCommand = new DelegateCommand(this.ShowListView);
     
                this.pages = new ObservableCollection<FramePage>();
                pages.Add(new FramePage("Icon View", "/XYZ.UserManagementModule;component/Views/UserIconView.xaml"));
                pages.Add(new FramePage("List View", "/XYZ.UserManagementModule;component/Views/UserListView.xaml"));
     
                //// Set the default view to the Icons View page
                this.SelectedPage = this.pages[0];
            }
     
    /// <summary>
            /// Gets or sets the selected page to display in the frame
            /// </summary>
            public FramePage SelectedPage
            {
                get
                {
                    return GetProperty(() => this.SelectedPage);
                }
     
                set
                {
                    SetProperty(() => this.SelectedPage, value);
                }
            }
            /// <summary>
            /// Gets the pages collection that can be displayed in the transition frame
            /// </summary>
            public ObservableCollection<FramePage> Pages
            {
                get
                {
                    return this.pages;
                }
            }
     
    /// <summary>
            /// Shows the Icon view page in the transition frame
            /// </summary>
            private void ShowIconView()
            {
                this.SelectedPage = this.pages[0];
            }
     
            /// <summary>
            /// Shows the List view page in the transition frame
            /// </summary>
            private void ShowListView()
            {
                this.SelectedPage = this.pages[1];
            }


    Now i can navigate to the UserIconView and UserListView pages, thats nto a problem. The problem is that when i transition to any of these pages, in the code-behind, i have 2 constructors defined like this:

    /// <summary>
            /// Initializes a new instance of the <see cref="UserListView"/> class.
            /// </summary>
            public UserListView()
            {
                this.InitializeComponent();
            }
     
            /// <summary>
            /// Initializes a new instance of the <see cref="UserListView"/> class.
            /// </summary>
            /// <param name="userManagementViewModel">View model for <see cref="UserListView"/></param>
            public UserListView(UserManagementViewModel userManagementViewModel)
                : this()
            {
                this.DataContext = userManagementViewModel;
            }


    The problem is that it only hits the Default constructor, the second user defined constructor is not fired at all, so basically i am not able to access my view model for these views.

    Any help would be appreciated.
  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 03 Nov 2011 Link to this post

    Hi Jinish,

    Are you able to get the correct behavior if you replace the RadTransitionControl with a ContentControl?

    Greetings,
    Valeri Hristov
    the Telerik team

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

  3. DevCraft banner
  4. Jinish
    Jinish avatar
    3 posts
    Member since:
    Feb 2011

    Posted 03 Nov 2011 Link to this post

    Hi Valeri,

    Yes, the problem apparently seems also with a ContentControl. Will need to dig a bit more into it.
  5. Jinish
    Jinish avatar
    3 posts
    Member since:
    Feb 2011

    Posted 03 Nov 2011 Link to this post

    Solved the problem by making the Frame a Prism region and using the RegionManager's "RequestNavigate" method to navigate to the view. That seems to work fine, although, still couldnt figure out what was wrong in the original approach.
Back to Top