Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
130
XamDiagram: Programmatically perform "Bring to Front/Back" on diagram items
posted

I am building a diagram based on the XamDiagram control, and I am building a custom version of the OptionsPane to modify properties on custom diagram items.

More specifically, I would like to add my own buttons for "Bring Forward/Backward" and "Bring to Front/Back," like the buttons that exist in the built-in OptionsPane. However, I have not found a clear way to execute those actions programmatically for a diagram item. 

Is there a way to do this?

Parents
  • 130
    Offline posted

    Followup:

    From what I can tell, it looks like the built-in "Bring Forward/Backward" buttons simply increment/decrement the DiagramItem.ZIndex property, so I decided to try using the Zindex property to write the logic for simulating those actions.

    However, now I'm running into a different problem. I am using two-way data binding with my own data to populate the XamDiagram, and I need to be able to set the ZIndex in my own data, which would then reflect back to the DiagramItem.ZIndex property, and vice versa.

    So my data object looks similar to this:

    class CustomDiagramItem: INotifyPropertyChanged
    {
      public int ZIndex {get; set; }

      public string Text { get; set; }

      public Brush Fill { get; set; }
      // etc.

    }

    I am then setting these custom objects in the Content property of the DiagramItem objects, as per the Xam Diagram documentation here: https://ko.infragistics.com/help/wpf/xamdiagram-binding-to-nodes-and-connections-data-with-references

    So the data binding in my xaml looks something like this:

    <ig:XamDiagram.NodeDefinitions>
      <ig:NodeDefinition TargetType="{x:Type local:CustomDiagramItem}"
                                    DisplayMemberPath="Text">
        <ig:NodeDefinition.NodeStyle>
          <Style TargetType="ig:DiagramNode">
            <Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource Self}, Path=Content.Fill, Mode=TwoWay}" />
            <Setter Property="ZIndex" Value="{Binding RelativeSource={RelativeSource Self}, Path=Content.ZIndex, Mode=TwoWay}" />
          </Style>
        </ig:NodeDefinition.NodeStyle>
      </ig:NodeDefinition>
    </ig:XamDiagram.NodeDefinitions>

    However, while my data binding has been working correctly, when I added the data binding for ZIndex, it didn't work. The ZIndex property updates in the DiagramItem when using the "Bring Forward/Backward" buttons, but its corresponding bound property in the CustomDiagramItem class does not update.

Reply Children