locked
Is that a bad Practice ? RRS feed

  • Question

  • Hello World 

    i am little bit confuse from what i am doing. Actually i need to bind RadChart Control using MVVM Model some propertise of RadChart not allow binding using MVVM binding they allow Code Behind Binding like ChartArea.DataSeries. So i found an another idea to bind that RadChart using MVVM. Actally on lu LayoutRoot (Grid) Loaded event i have called a Command using MVVM EventToCommand and i am passing Layout Root as an parameter of command in Command i have find that Chart Control using LayoutRoot.FindName("RadChart")...

    I just wannt to know is that a good practice ???????

    here is my xaml code

    <Intr:Interaction.Triggers>
                <Intr:EventTrigger EventName="Loaded">
                    <Custom:EventToCommand Command="{Binding ElementName=LayoutRoot, Path=DataContext.LoadedCommand, Mode=OneWay}" PassEventArgsToCommand="True" CommandParameter="{Binding ElementName=LayoutRoot}"></Custom:EventToCommand>
                </Intr:EventTrigger>
            </Intr:Interaction.Triggers>

    here is my ViewModel Code

     public void OnLoaded(object sender) {
                if (sender != null) {
                    var LayoutRoot = ((Grid)sender);
                    var chart = LayoutRoot.FindName("rcReviewBatch");
                    if (chart != null) {
                        this.RadChartControl = (RadChart)chart;
                    }
                }
            }
    Tuesday, February 14, 2012 2:31 AM

All replies

  • Hi ravi010mittal,

    As you mentioned, some propertise of RadChart not allow binding using MVVM binding .

    And I suggest you to use Code Behind Binding.

    Because I think MVVM is a good Practice (views and logics will not influence each other), but your way of using MVVM is not using Concepts and Advantages of MVVM

    So, do not be forced to use MVVM, suitable is OK. Try Code Behind Binding.

    Wednesday, February 15, 2012 10:23 PM
  • thanks for your reply....i cannot stop using MVVM Pattern...thats Client's requirement for this project...is their any other way to complete sund kinda exceptions

    Thursday, February 16, 2012 2:14 AM
  • Hi,

    The way you mentioned in your original post I think maybe the only way to solve the issue.

    I also suggest you to connect Telerik for more help.

    Maybe they can provide a way to bing by MVVM

    Thursday, February 16, 2012 2:19 AM
  • ok..

    Can you please tell me How do i use navigation using MVVM Pattern. I have used this below post but i cannot find success

    http://garfoot.com/blog/2010/09/silverlight-navigation-with-the-mvvm-pattern/#comment-1023

    Thursday, February 16, 2012 2:30 AM
  • Hi,

    Have downloaded the sample below of the link?

    Sample code: NavigationSample

    I can run the sample.

    Thursday, February 16, 2012 3:39 AM
  • ya i have downloaded it.....i did the same but my code give me null exception on NavigationServices Property

    Thursday, February 16, 2012 9:12 AM
  • Did you get the null exception in the sample in the above post?

    Which code get the null exception? could you show me in order to find what is wrong.

    Friday, February 17, 2012 12:41 AM
  • Sample is running great...but when i use same code in my application then it comes with null exception......i have create a base class and inherit that base class to every ViewModel class...i have used INvaigable in my base class.....

    Friday, February 17, 2012 12:54 AM
  • Hi ,

    the NavigationService inited in the Navigator.cs file:

    if (navSource != null)
                {
                    navSource.NavigationService = new NavigationService(page.NavigationService);
                }

    Please check it .

    Friday, February 17, 2012 1:06 AM
  • The Source is set in the beginning of every page:

    Navigation:Navigator.Source="{Binding}"
    
    Friday, February 17, 2012 1:07 AM
  • ya i know....navigator,cs inited successfully....but i dnt know why NavigationService giving me null exception....i have inherit the namespace on my xaml page and this Code line also

    Navigation.NavigationServices.Source="{Binding}"

    actually i have a MainPage.xaml and my navigation pages....

    Friday, February 17, 2012 1:16 AM
  • Hi,

    Could you share your project to skydrive for me ?

    I cannot target the problem directly~

    Friday, February 17, 2012 1:19 AM
  • Please give a breakpoint to the code :

    navSource.NavigationService = new NavigationService(page.NavigationService);
    

    in order to see whether it runs

    Friday, February 17, 2012 1:32 AM
  • i did everything but in vain....

    Friday, February 17, 2012 2:28 AM
  • ill explain my senario

    do i have to put Navigation.NavigationService.Source="{Binding}" to every page..? Actually i put this line of code to two pages only from where i have to navigate and to Page address. 

    thats my project sanerio

    i have Login.xaml which is separte from other Content Pages...

    Master.xaml Which has a Content Frame

    Dashboard.xaml (First Content Page that Loads in Master.Page's Content Frame) when this page is loads Navigator.cs Inited. When i checked navSource.NavigationService, it has the reference of MasterViewModel not DashBoardViewModel but Page address is DashBoard. When i am trying to navigation from DashBoardViewModel to my second Page then i got the null exception

    this is my baseClass

    public class ViewModelBase : INotifyPropertyChanged , Navigation.INavigable
        {
    
            public bool IsDesignTime
            {
                get { return DesignerProperties.IsInDesignTool; }
            }
    
            public event PropertyChangedEventHandler PropertyChanged;
            public virtual void OnPropertyChanged(string propertyName)
            {
                var propchanged = PropertyChanged;
                if (propchanged != null)
                {
                    propchanged(this, new PropertyChangedEventArgs(propertyName));
    
                }
    
            }
            public Navigation.INavigationService NavigationService
            {
                get;
                set;
            }
        }

    this is my DashBoradViewModel Class

    public class DashBoardViewModel : Client.ViewModel.ViewModelBase
    Friday, February 17, 2012 2:38 AM
  • do u have a Skype id if you mind...so i can talk to you directly

    Friday, February 17, 2012 2:39 AM
  • Hi,

    I cannot use the Skype in my work environment.

    It would be appreciated if you can create a new project with simple code that can reproduce the exception and share it with me through the skydrive.

    Friday, February 17, 2012 2:46 AM
  • ok i will ping you when its done....

    Friday, February 17, 2012 3:37 AM