When I expand the column, to view the child table, I get the error: A TwoWay or OneWayToSource binding cannot work on the read-only property 'AddressFamily' of type 'System.Net.IPEndPoint'.
I had the same error on the parent table - but got around it by explicitly defining the columns and the column bindings as one-way. Not really sure why that was required either, but it worked. But, can't figure out how to do that for the child table. And, I'm not sure if this was the correct approach anyway.
I get this scenario to work correctly with DataSets - but don't want to have to create DataSets for the 50+ objects I need to do this for.
Any thoughts?
The datasource is a collection of custom objects.
XAML is...
<Window x:Class="WpfApplication1.Window1" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
Title="Window1" Height="313" Width="420" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" WindowStyle="ThreeDBorderWindow" SizeToContent="Manual"> |
<Grid> |
<Grid.Resources> |
</Grid.Resources> |
<telerik:RadGridView |
Name="radGridView1" |
AllowDrop="False" |
ColumnsWidthMode="Auto" |
AutoGenerateColumns="False" > |
<telerik:RadGridView.Columns> |
<telerik:GridViewDataColumn |
HeaderText="Name" |
DataMemberBinding="{Binding Path=Name, Mode=OneWay}"/> |
<telerik:GridViewDataColumn |
HeaderText="HostName" |
DataMemberBinding="{Binding Path=HostName, Mode=OneWay}" /> |
<telerik:GridViewDataColumn |
HeaderText="Type" |
DataMemberBinding="{Binding Path=Type, Mode=OneWay}" /> |
<telerik:GridViewDataColumn |
HeaderText="Domain" |
DataMemberBinding="{Binding Path=Domain, Mode=OneWay}" /> |
</telerik:RadGridView.Columns> |
</telerik:RadGridView> |
</Grid> |
</Window> |
code behind is:
public partial class Window1 : Window |
{ |
Browser browser; |
BindingList<OtogramService> servicesBindingList = new BindingList<OtogramService>(); |
public Window1() |
{ |
InitializeComponent(); |
// Create the browser |
browser = new Browser("_http._tcp"); |
// Hook the Updated event. |
browser.Updated += new Browser.EventHandler(browser_Updated); |
//create the relationship |
var detailDefinition = new Telerik.Windows.Controls.GridViewTableDefinition(); |
detailDefinition.Relation = new Telerik.Windows.Data.PropertyRelation("Addresses"); |
radGridView1.TableDefinition.ChildTableDefinitions.Add(detailDefinition); |
radGridView1.ItemsSource = servicesBindingList; |
} |
void browser_Updated2(Browser sender, OtogramBrowserEventArgs e) |
{ |
switch (e.otogramBrowserEvent) |
{ |
// note - it is possible to get an Updated* event |
// before the Add event. |
case OtogramService.Event.UpdatedAddress: |
case OtogramService.Event.UpdatedTextRecord: |
case OtogramService.Event.Add: |
{ |
try |
{ |
// if we have one just update it |
var z = (from p in servicesBindingList where p.Name == e.otogramService.Name select p).Single(); |
z = e.otogramService; |
} |
catch |
{ |
// if we don't have one already - add a new one. |
servicesBindingList.Add(e.otogramService); |
} |
} |
break; |
case OtogramService.Event.Remove: |
{ |
// if we have one - remove it. |
var z = from p in servicesBindingList where p.Name == e.otogramService.Name select p; |
if (z.Count() != 0) |
{ |
servicesBindingList.Remove(z.First()); |
} |
} |
break; |
} |
} |
private delegate void UpdateBrowser(Browser sender, OtogramBrowserEventArgs e); |
// required because WPF must execute one on one thread. |
// This puts the callback into the WPF thread's dispatch queue. |
void browser_Updated(Browser sender, OtogramBrowserEventArgs e) |
{ |
UpdateBrowser func = browser_Updated2; |
this.Dispatcher.BeginInvoke(func, new object[] { sender, e }); |
} |
} |