Hello, if I put the XamGrid into TilePane the ItemSource give me an error:
Riferimento a un oggetto non impostato su un'istanza di oggetto.
If put then XamGrid outer of TilePane the ItemSource is Ok
This is the Code:
<ig:XamTileView ColumnsInPage="2" RowsInPage="2" Name="tlOre"><ig:TilePane Header="Fascia oraria" Name="tpOre" ><ig:XamGrid Name="dgOre" AutoGenerateColumns="False" VerticalAlignment="Stretch"><ig:XamGrid.Columns><ig:TextColumn HeaderText="Ora" Key="Descrizione"/><ig:TextColumn HeaderText="Venduto" Key="Valore"/></ig:XamGrid.Columns></ig:XamGrid></ig:XamTileView>
VB
Private Sub mService_GetFasciaOrariaCompleted(ByVal sender As Object, ByVal e As ServiceReference1.GetFasciaOrariaCompletedEventArgs) Handles mService.GetFasciaOrariaCompleted
dgOre.ItemSource = e.Results
End sub
Thank you
Alessandro
(italy)
I'm not sure without having the whole sample to debug but I notice that in the LoadbarChartData method you are checking if the grid is null rather than the chart. If, by the point this method is called, you have not yet instantiated myGrid then the DataSource for the chart would never be set.
Hi Jason,
Thanks for the reply.
As i told i am using the XamTileView control. Now I am adding four TilePane. In Four TilePane add different control. Like TilePane1 – XamGrid, TilePane – XamChart etc.How can bind XamChart thoguh these different control through the list. I am mention the code here for XamChart binding
----------------------------------------------------------------------------
XAML Code
<ig:TilePane Header="GridPane" Name="tpGridPane2" Loaded="tpGridPane_Loaded"> <igWebChart:XamWebChart x:Name="barChart" HorizontalAlignment="Center" Width="600" Height="400" Grid.Row="2" Loaded="barChart_Loaded"> <igWebChart:XamWebChart.Series> <igWebChart:Series x:Name="series" ChartType="Bar" DataMapping="Value=CopiesSold;Label=Genre" Label="Books sold per month" > </igWebChart:Series> </igWebChart:XamWebChart.Series> </igWebChart:XamWebChart>
</ig:TilePane>
--------------------------
private void barChart_Loaded(object sender, RoutedEventArgs e) { _XamWebChart = (XamWebChart)sender; LoadbarChartData(); } private void LoadbarChartData() { if (myGrid != null) _XamWebChart.Series[0].DataSource = sells; } public class BooksStore { public string Genre { set; get; } public int CopiesSold { set; get; }
public BooksStore(string genre, int sold) { this.Genre = genre; this.CopiesSold = sold; } }
private void populateData() { sells.Add(new BooksStore("Poetry", 100)); sells.Add(new BooksStore("Fiction", 256)); sells.Add(new BooksStore("Biography", 34)); sells.Add(new BooksStore("Fantasy", 323)); sells.Add(new BooksStore("Autobiography", 12)); sells.Add(new BooksStore("Mythology", 86)); }---------------------------------------------------------------------
Whats probs here ? Is any thing missing
Kindly tell me the suggestion.
There are a few things that need to be modified for this approach to work. First, the constructor of the Page is too early to use the FindName method. At this point, the controls have not been created so even if FindName can find them they would still be null. You could resolve this by moving the logic in to the Loaded event of the TilePane.
However, if your goal is to load data in to the grid then a better approach may be to wire up the grid's Loaded event. At this point you can then access the sender of the event which will be the XamGrid and connect the data to that.
I also want to note that in the code provided myGrid is only really instantiated in the constructor and falls out of scope once the constructor is executed. This should instead be created outside of the constructor. Keep in mind though that setting myGrid = new XamGrid() in your LoadXmlData method will break this link.
I've attached a modified sample that demonstrates using both the XamGrid's Loaded method and the TilePane's Loaded method.
Please let me know if I can be of any further assistance.
Hi,
I read your reply. I used the same code.
In XamGrid i am trying to bind the itemsource but its not binding.
Here i am mention code
-----------------------------------------------------------------------
public Test() { InitializeComponent(); XamGrid myGrid = tlOre.Items[0].FindName("dgOre") as XamGrid; //XamGrid myGrid = tpOre.FindName("dgOre") as XamGrid; LoadXMLData();
} private void LoadXMLData() { XDocument doc = XDocument.Load("Xml/Products.xml");
var data = (from d in doc.Descendants("Products") select new Product { SKU = d.Element("ProductID").Value, Name = d.Element("ProductName").Value, Category = d.Element("Category").Value, Supplier = d.Element("Supplier").Value, QuantityPerUnit = d.Element("QuantityPerUnit").Value }).ToList<Product>();
myGrid = new XamGrid(); myGrid.ItemsSource = data;
}
I am not able get the record.
Hello Alessandro,
To access the XamGrid you can use the FindName method, passing in the name you assigned to the XamGrid:
XamGrid myGrid = tpOre.FindName("dgOre") as XamGrid;
The reason for this is that the namescope of the XamGrid gets modified when you place it within the TilePane.
For more information about the FindName method, please see the following MSDN article:
<http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.findname(VS.95).aspx>
For more information about namescopes in Silverlight, please see the following MSDN article:
<http://msdn.microsoft.com/en-us/library/cc189026(VS.95).aspx>
Please let me know if you have any further questions or concerns about this matter.