locked
need to pass ID from one view model to another using Dependancy property

    Question

  • Hi Every one , 

    I need to pass string id from my one view model to another as i have user control and its view model separate to finish task . 

    Here how much i did using dependency  property 

      public string Module
            {
                get { return (string)GetValue(ModuleName); }
                set
                {
                    SetValue(ModuleName, value);
                }
            }
    
            public static readonly DependencyProperty ModuleName =
                DependencyProperty.Register("Module", typeof(string), typeof(UcPhotos),
                new PropertyMetadata(string.Empty, OnModuleNameChanged));
    
            private static void OnModuleNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                (d as UcPhotos).ModuleId = e.NewValue.ToString();
                (d as UcPhotos).id = e.NewValue.ToString();
            }
    
     private string _ModuleId;
            public string ModuleId
            {
                get
                { return _ModuleId; }
    
                set
                {
                    if (_ModuleId == value)
                    {
                        return;
                    }
    
                    ((UcPhotoViewModel)this.DataContext).Module = value.ToString();
                    _ModuleId = value;
                }
            }
    

    Where for user control i have property which i ll use for further . the problem is whiling sending value from my page , if it is hard coded i am avail to get . but from my page if i am binding as my requirement its not avail to set there . ie .

                        <uc:UcPhotos x:Name="UcPhotoGrd" PropertyId="{Binding TskHeader.tskhdrid,Source={StaticResource ViewModel}}" Module="TASK" Visibility="{Binding PhotoGridvisible,Converter={StaticResource BoolToVisibleConverter}}"></uc:UcPhotos>

    Now Task I have given hard coded which i am able to see not the binded property TskHeader.tskhdrid. Please guys help me out if you have any other approach or further suggestion.  

    ((UcPhotoViewModel)this.DataContext).Module

    Wednesday, November 12, 2014 7:07 AM

All replies

  • Hi Shivam,

    I am not sure what are you doing about the binding. Does you want to edit the Module property of the UcPhotos control to change something else? There is less information for me to understand your problem.

    Can you send a project for reproduction? Use your OneDrive and share a link here. I will look into it.

    Thank you for understanding.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Thursday, November 13, 2014 3:09 AM
    Moderator