0

Third try to describing problem:

I have some class for view models:

public class Node : INotifyPropertyChanged
    {
        Guid NodeId { get; set; }

        public string Name { get; set; }

    }

public class Connection: INotifyPropertyChanged
    {
        public Node StartNode { get; set; }
        public Node EndNode { get; set; }
    }

public class SettingsPackModel
{
        public List<Node> Nodes { get; private set; }
        public List<Connection> Connections { get; private set; }
}

I also have some templates to displays these models:

<DataTemplate DataType="{x:Type vm:Node}">…</DataTemplate>
<DataTemplate DataType="{x:Type vm:Connection}">
 <my:ConnectionElment StartNodeElment="???" EndNodeElment="???"> 
</my:ConnectionElment>
<DataTemplate>

But the problem is that DataTemplate for Connection need reference ot two element of type UIElement , how can I pass these two, how can I fill ??? in above expression?

Edit: I actually want to hide that's part in this try, but as I describe it there: Sunchronizing view model and view. I would use something like this :

<ItemsControl    ItemsSource="{Binding AllElements}" 
ItemContainerStyle="{StaticResource ElementThumbVMDataTemplateStyle> 
        <ItemsControl.ItemsPanel> 
            <ItemsPanelTemplate> 
                <kw:DiagramCanvas /> 
            </ItemsPanelTemplate> 
        </ItemsControl.ItemsPanel> 
    </ItemsControl> 
<Style  x:Key="ElementThumbVMDataTemplateStyle" TargetType="ContentPresenter"> 
                <Setter Property="Canvas.Left"  Value="{Binding CanvasLeft,Mode=TwoWay}" /> 
                <Setter Property="Canvas.Top"  Value="{Binding CanvasTop,Mode=TwoWay}" />             </Style > 

And something like this for Node DataTemplate:

<DataTemplate DataType="{x:Type vm:Node}"> 
                <kw:ElementThumb Canvas.Left="{Binding CanvasLeft,Mode=TwoWay}" 
                                 Canvas.Top="{Binding CanvasTop,Mode=TwoWay}"> 
                </kw:ElementThumb> 
            </DataTemplate> 

Canvasleft and CanvasTop are properties that exist in Node and also ElementThumb classes.

Community
  • 1
  • 1
mehran
  • 1,314
  • 4
  • 19
  • 33

1 Answers1

0

Placing an object of the type you are creating a DataTemplate for inside the DataTemplate itself is quite pointless. DataTemplates are there for the creation of a visual representation of your data, so you first need a concept of how you want to visualize your Nodes and Connections.

H.B.
  • 166,899
  • 29
  • 327
  • 400