Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
295
XamGrid Databinding AddNewRowItemTemplate Textblock Text Problem
posted

Hello!

 

I'm having quite a bit of trouble trying to databind a string to the Textblock Text of an AddNewRowItemTemplate Datatemplete. My code will probably be easier to understand, here is a little snippet:

 

What I'm trying to do is have a webservice autopopulate the textblock of the AddNewRowItemTemplate cell corresponding to the "ItemName" column. I've databound hundreds of times in this silverlight application and it has all worked perfectly. The only things new here is that I'm databinding to an AddNewRowItemTemplate which exists in a XamGrid whose ItemSource is already bound to a list.

 

I obviously don't fully understand whats going on in the background, but I'm assuming that because the AddNewRowItemTemplate is considered a row in "igGrid", the Databinding paths are all messed up. I've to fix this by adding Path=DataContext.NewItemName, but it does nothing.

 

Basically, the block stays blank. However, if i give it a value, TextBlock Text="Test Name", Test Name pops up in the cell.

 

Could someone help me find whats wrong with my databinding?

 

<Grid x:Name="LayoutRoot" Background="White" SizeChanged="LayoutRoot_SizeChanged">

<ig:XamGrid x:Name="igGrid" ItemsSource="{Binding ItemList}" VerticalAlignment="Top" >

<ig:XamGrid.AddNewRowSettings>

<ig:AddNewRowSettings AllowAddNewRow="Bottom" IsEnterKeyEditingEnabled="False" />

</ig:XamGrid.AddNewRowSettings>

             

<ig:XamGrid.Columns>

<ig:TextColumn Key="ItemName" IsSorted="Ascending">

<ig:TextColumn.AddNewRowItemTemplate>

<DataTemplate>

<TextBlock Text="{Binding NewItemName}"/>

</DataTemplate>

</ig:TextColumn.AddNewRowItemTemplate>

<ig:TextColumn.HeaderTemplate >

<DataTemplate>

<TextBlock Text="Item Name"/>

</DataTemplate>

</ig:TextColumn.HeaderTemplate>

</ig:TextColumn>

...

 

In the code-behind I have relating to this:

 

        #region Constructor

        public CycleWells(MASL.View.MainPage Main)

        {

            InitializeComponent();

            this.viewmodel = new ItemViewModel();

            this.DataContext = this.viewmodel;

        }

        View.ViewModel viewmodel;

        #endregion Constructor

 

 and in my ViewModel, I have these two relevant properties

 

        private string newitemname_;

        public string NewItemName

        {

            get

            {

                return this.newitemname_;;

            }

            set

            {

                if (this.newitemname_;!= value)

                {

                    this.newitemname_;= value;

                    OnPropertyChanged("NewItemName");

                }

            }

        }

        private IEnumerable<Item> ItemList_;

        public IEnumerable<Item> ItemList

        {

            get

            {

                return this.ItemList_;

            }

            set

            {

                if (this.ItemList_ != value)

                {

                    this.ItemList_ = value;

                    this.OnPropertyChanged("ItemList");

                }

            }

        }

 

If it isn't clear, in this example, ItemName is a property in the Item class.

 

Thank you very much!

Parents Reply Children