Hi,
I tried to work with bound Properties on ConnectorShapes.
This works fine - as Long as I do not clear the InternalItems / InternalLinks in the Graph source.
First the Style (part of it)
Now my (simple) classes:
(forget about INPBase - it's just an implementation of INotifyPropertyChanged
The Node:
The Link:
The Tree:
Last not Least I have a "ViewModel" like this:
(of course in real code things are handled via commands - but that doesn't matter)
Everything works fine - as long as I'm not resetting the tree.
After this I get the debug message:
So it seems as if clearing the collections move the datacontext "on step up".
My Binding is simple the UserControl (hosting the diagram) has an Instance of TestVM as DataContext and the Diagram is bound like this:
Thank you
Manfred
I tried to work with bound Properties on ConnectorShapes.
This works fine - as Long as I do not clear the InternalItems / InternalLinks in the Graph source.
First the Style (part of it)
<Style TargetType="telerik:RadDiagramConnection" > <!----> <Setter Property="Visibility" Value="{Binding Visibility, Mode=TwoWay}" /> <!---->Now my (simple) classes:
(forget about INPBase - it's just an implementation of INotifyPropertyChanged
The Node:
public class Item : INPBase { #region Content private string _Content; public string Content { get { return _Content; } set { Set(ref _Content, value); } } #endregion }The Link:
public class Link : INPBase, ILink<Item> { public Visibility Visibility { get; set; } public Item Source { get; set; } public Item Target { get; set; } object ILink.Source { get { return ((object)Source); } set { if (!((object)Source).Equals(value)) { Source = value as Item; } } } object ILink.Target { get { return ((object)Target); } set { if (!((object)Target).Equals(value)) { Target = value as Item; } } } public Link() { Visibility = Visibility.Visible; }}The Tree:
public class TestTree : INPBase, IGraphSource { public ObservableCollection<Item> InternalItems { get; private set; } public ObservableCollection<Link> InternalLinks { get; private set; } public Item RootNode { get; private set; } public System.Collections.IEnumerable Items { get { return (InternalItems); } } public IEnumerable<ILink> Links { get { return(InternalLinks); } } public TestTree() { InternalItems = new ObservableCollection<Item>(); InternalLinks = new ObservableCollection<Link>(); BuildTree(); } private void BuildTree() { RootNode = new Item() { Content = "One" }; Item iTwo = new Item() { Content = "Two" }; Item iThree = new Item() { Content = "Three" }; Item iFour = new Item() { Content = "Four" }; InternalItems.Add(RootNode); InternalItems.Add(iTwo); InternalItems.Add(iThree); InternalItems.Add(iFour); InternalLinks.Add(new Link() { Target = RootNode, Source = iTwo }); InternalLinks.Add(new Link() { Target = RootNode, Source = iThree }); InternalLinks.Add(new Link() { Target = RootNode, Source = iFour }); } public void RebuildTree() { InternalLinks.Clear(); InternalItems.Clear(); BuildTree(); } public void AddNodeWithLink() { Item iNew = new Item() { Content = "I" + InternalItems.Count.ToString() }; Item iSource = InternalItems.First(); InternalItems.Add(iNew); InternalLinks.Add(new Link() { Target = iSource, Source = iNew }); } }Last not Least I have a "ViewModel" like this:
public class TestVM : INPBase { private TestTree _TestTree; public TestTree TestTree { get { return _TestTree; } } public TestVM() { _TestTree = new TestTree(); } public void AddNode() { _TestTree.AddNodeWithLink(); } public void Rebuild() { _TestTree.RebuildTree(); }}Everything works fine - as long as I'm not resetting the tree.
After this I get the debug message:
System.Windows.Data Error: 40 : BindingExpression path error: 'Visibility' property not found on 'object' ''TestVM' (HashCode=61656587)'. BindingExpression:Path=Visibility; DataItem='TestVM' (HashCode=61656587); target element is 'RadDiagramConnection' (Name=''); target property is 'Visibility' (type 'Visibility')
So it seems as if clearing the collections move the datacontext "on step up".
My Binding is simple the UserControl (hosting the diagram) has an Instance of TestVM as DataContext and the Diagram is bound like this:
<Grid DataContext="{Binding}" x:Name="grdHolder"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Button Content="Add node" VerticalAlignment="Center" HorizontalAlignment="Left" Click="AddNode_Click" /> <Button Content="Rebuild" VerticalAlignment="Center" HorizontalAlignment="Center" Click="Rebuild_Click" /> <Button Content="Layout" VerticalAlignment="Center" HorizontalAlignment="Right" Click="Layout_Click" /> <telerik:RadDiagram x:Name="dG" GraphSource="{Binding TestTree}" Grid.Row="1"/> </Grid>Thank you
Manfred