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 >
<TextBlock Text="Item Name"/>
</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
return this.ItemList_;
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!
By the way, those ";" characters in the NewItemName property are typos, they don't acutally exist in my code.
Hello,
It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking into your post, but sice I cannot be completely sure how your data is organized I am not able to conclude whar can casue your issue, so if this is still an issue for you, could you please send an isolated sample project, where the issue is reproduced, so I can investigate it further for you.
Feel free to write me if you have further questions.
Thank you for your reply. I no longer need this functionality, but for the future, if one needs a single cell in the entire XamGrid databound to a specific item, outside the ItemSource binding, how would one achieve this goal? What I needed was a cell in the "AddNewRow" row on the bottom of the grid, specifically the cell in the first column, exceptionally bound to a specific string.
Any ideas how I can databind one cell to a specific string?
Thanks.
In order to achive this functionality you can create a Style for the CellValuePresenter and bind its ValueProperty via the DataContext of the XamDataGrid to a Property and by setting key of the Style you can apply it to a specific Field by setting its Settings' CellValuePresenterStyle.
Hope this helps you.