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

RadWindow not binding to ViewModel (MVVM) Property (Entity)

2 Answers 286 Views
Window
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 1
Jose asked on 02 Feb 2011, 04:53 PM
Hello,
After an almost self explanatory thread title...Hands on code...

this is my XAML

<telerik:RadWindow x:Name="winNewCustomerWindow" Header="New Customer..." WindowStartupLocation="CenterOwner" DataContext="{Binding Path=RetailCustomer, Mode=TwoWay}" >
            <StackPanel Orientation="Vertical">
                <StackPanel Orientation="Horizontal" Margin="5">
                    <TextBlock Text="First Name:" />
                    <TextBox Width="100" Text="{Binding Path=FirstName, Mode=TwoWay}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="5">
                    <TextBlock Text="Last Name:" />
                    <TextBox Width="100" Text="{Binding LastName, Mode=TwoWay}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="5" HorizontalAlignment="Right">
                    <Button Content="SAVE" Command="{Binding SaveEntityCommand}" />
                </StackPanel>
            </StackPanel>
        </telerik:RadWindow>
in my XAML i have tried the Binding with Path=, without it, all possible ways.
this is my ViewModel for this XAML

[PartCreationPolicy(CreationPolicy.NonShared)]
[Export(ViewModelTypes.MainAgentPageViewModel)]
public class MainAgentPageViewModel : IFGViewModelBase
{
      
    IRetailModel _model;
      
    [ImportingConstructor]
    public MainAgentPageViewModel(IRetailModel model)
    {
        _model = model;
        Messenger.Default.Register<NewEntityArgs>(this, OnNewCustomer);
    }
    #region Methods
    public void OnNewCustomer(NewEntityArgs entityArgs)
    {
        RetailCustomer = (RetailCustomer)entityArgs.Entity;
        RetailCustomer.FirstName = "Test FirstName";
        RetailCustomer.LastName = "Test LastName";
        NotifyNewCustomer();
    }
    #endregion
    #region Properties
    public const string RetailCustomerPropertyName = "RetailCustomer";
    private RetailCustomer _retailCustomer = null;
    public RetailCustomer RetailCustomer
    {
        get
        {
            return _retailCustomer;
        }
        set
        {
            if (_retailCustomer == value)
            {
                return;
            }
            _retailCustomer = value;
            // Update bindings, no broadcast
            RaisePropertyChanged(RetailCustomerPropertyName);
        }
    }
    #endregion
    #region Events
    public event RoutedEventHandler NewCustomer;
    public void NotifyNewCustomer()
    {
        if (NewCustomer != null) { NewCustomer(this, new RoutedEventArgs()); }
    }
    #endregion
}

this is my XAML Codebehind

    public partial class MainAgentPage : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the MainAgentPage class.
        /// </summary>
        public MainAgentPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(OnLoaded);
            if (!IFGViewModelBase.IsInDesignModeStatic)
                CompositionInitializer.SatisfyImports(this);
        }
  
        void OnLoaded(object sender, RoutedEventArgs e)
        {
            DataContext = ViewModel;
            ViewModel.NewCustomer += new RoutedEventHandler(OnNewCustomer);
        }
  
        void OnNewCustomer(object sender, RoutedEventArgs e)
        {
            winNewCustomerWindow.ShowDialog();
        }
  
        [Import(ViewModelTypes.MainAgentPageViewModel)]
        public MainAgentPageViewModel ViewModel
        { get; set; }
}

Thing is that i should be able to see in my textboxs the string i passed when i first created the RetailCustomer object... but it's not happening.
Something curious thou. When i set a step on my XAML code behind... right at the event when i showdialog my window, the DataContext was my RetailCustomer object... which means SOMEHOW it's connecting to the ViewModel, but it's not showing the values.

I am following TaskIt application as a model for my application... it works for him, but not for me. Where am i screwing things up here? i almost have a REPLICA of his code but i cant get the radwindow to work.

Thank you

2 Answers, 1 is accepted

Sort by
0
Jose
Top achievements
Rank 1
answered on 03 Feb 2011, 12:03 AM
I created a RadWindow usercontrol following the directions on the Documentation but it didn't work.
:(
0
George
Telerik team
answered on 07 Feb 2011, 04:06 PM
Hi Jose,

 
I would suggest you to refer to the following blog post - http://blogs.telerik.com/blogs/posts/10-03-24/mvvm_in_task-it.aspx

I hope this helps.

All the best,
George
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
Window
Asked by
Jose
Top achievements
Rank 1
Answers by
Jose
Top achievements
Rank 1
George
Telerik team
Share this question
or