Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic UserControl from Ruller with diagram (Read 4429 times)
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
UserControl from Ruller with diagram
Jan 25th, 2010 at 2:43pm
Print Post  
I implement a user control
Code
Select All
<UserControl x:Class="Diagrammer.TPDEDiagram"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mf="clr-namespace:MindFusion.Diagramming.Wpf;assembly=MindFusion.Diagramming.Wpf"
    xmlns:cmds="clr-namespace:Diagramm.InterfaceCommands"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:Diagrammer="clr-namespace:Diagrammer">
    <UserControl.CommandBindings>
        <CommandBinding Command="cmds:MenuCommands.ZoomIn" Executed="ZoomIn_Executed"/>
        <CommandBinding Command="cmds:MenuCommands.ZoomOut" Executed="ZoomOut_Executed"/>
        <CommandBinding Command="cmds:MenuCommands.Zoom100" Executed="Zoom100_Executed"/>
        <CommandBinding Command="cmds:MenuCommands.Undo" Executed="Undo_Executed" CanExecute="Undo_CanExecute"/>
        <CommandBinding Command="cmds:MenuCommands.Redo" Executed="Redo_Executed" CanExecute="Redo_CanExecute"/>
        <CommandBinding Command="cmds:DiagramCommands.MoveLeft" Executed="MoveLeft_Executed"/>
        <CommandBinding Command="cmds:DiagramCommands.MoveRight" Executed="MoveRight_Executed"/>
        <CommandBinding Command="cmds:DiagramCommands.MoveUp" Executed="MoveUp_Executed"/>
        <CommandBinding Command="cmds:DiagramCommands.MoveDown" Executed="MoveDown_Executed"/>
        <CommandBinding Command="cmds:MenuCommands.Copy" Executed="Copy_Executed" CanExecute="Copy_CanExecute"/>
        <CommandBinding Command="cmds:MenuCommands.Paste" Executed="Paste_Executed" CanExecute="Paste_CanExecute"/>
        <CommandBinding Command="cmds:MenuCommands.Cut" Executed="Cut_Executed" CanExecute="Cut_CanExecute"/>
    </UserControl.CommandBindings>
    <UserControl.Resources>
        <ObjectDataProvider x:Key="ArrowList" ObjectType="{x:Type Diagrammer:ArrowList}"/>
        <ObjectDataProvider x:Key="TextFmtList" ObjectType="{x:Type Diagrammer:TextFmtList}"/>
        <ObjectDataProvider x:Key="TextFontSizeList" ObjectType="{x:Type Diagrammer:TextFontSizeList}"/>
    </UserControl.Resources>
    <Grid>
        <mf:Ruler Name="m_Ruler" Margin="0,0,0,2" VerticalScaleVisible="Collapsed"
            HorizontalScaleVisible="Collapsed" Width="Auto" SizeChanged="OnRuler_SizeChanged">
            <mf:Ruler.Document>
                <mf:Diagram Name="m_Diagram" Height="Auto" Width="Auto"
                        ShowDisabledHandles="false"
                        ModificationStart="AutoHandles"
                        SnapToAnchor="OnCreateOrModify"
                        LinkHitDistance="3"
                        ShowGrid="False"
                        BackBrush="LightGray"
                        AlignToGrid="True"
                        AllowSelfLoops="False"
                        AllowDrop="True"
                        AllowSplitLinks="True"
                        AllowUnanchoredLinks ="False"
                        AllowUnconnectedLinks="False"
                        AutoScroll="True"
                        GridStyle="Points"
                        LinkStyle="Cascading"
                        AllowLinkCursor="Arrow"
                        AutoResize="AllDirections"
                        InplaceEditAcceptOnEnter="True"
                        InplaceEditCancelOnEsc="True"
                        AllowInplaceEdit="False"
                        DragDrop.DragOver="OnDiagram_DragOver"
                        DragDrop.Drop="OnDiagram_Drop"
                        LinkCreated="OnDiagram_LinkCreated"
                        LinkCreating="OnDiagram_LinkCreating"
                        SelectionChanged="OnDiagram_SelectionChanged"
                        ContextMenuOpening="OnDiagram_ContextMenuOpening"
                        KeyDown="OnDiagram_KeyDown"
                        EnterInplaceEditMode="OnDiagram_EnterInplaceEditMode"
                        NodeModified="OnDiagram_NodeModified"
                        NodeActivated="OnDiagram_NodeActivated"
                        NodeDeactivated="OnDiagram_NodeDeactivated"
                        NodeModifying="OnDiagram_NodeModifying">
                    <mf:Diagram.CommandBindings>
                        <CommandBinding Command="cmds:DiagramCommands.ShowProperties" Executed="ShowProperties_Executed"/>
                    </mf:Diagram.CommandBindings>
                    <mf:Diagram.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="&#1057;&#1074;&#1086;&#1081;&#1089;&#1090;&#1074;&#1072;..." Command="cmds:DiagramCommands.ShowProperties"/>
                        </ContextMenu>
                    </mf:Diagram.ContextMenu>
                </mf:Diagram>
            </mf:Ruler.Document>
        </mf:Ruler>
    </Grid>
</UserControl>
 


And first time in constructor of main window I call:
Code
Select All
            m_MainTabCtrl.SelectedIndex = AddTabItem("&#1053;&#1086;&#1074;&#1099;&#1081;.tpd");
 


And all is ok. But when user presses the toolbar button I try to add new tab item with this control.
But the diagram object doesn't created
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: UserControl from Ruller with diagram
Reply #1 - Jan 25th, 2010 at 2:44pm
Print Post  
Code
Select All
	  private void NewDgrm_Executed(object sender, ExecutedRoutedEventArgs e)
	  {
		m_MainTabCtrl.SelectedIndex = AddTabItem("&#1053;&#1086;&#1074;&#1099;&#1081;.tpd");
				TPDETabItem tabItem = m_MainTabCtrl.Items[m_MainTabCtrl.SelectedIndex] as TPDETabItem;
		tabItem.Diagram.Dirty = false;
		m_ToolBarNodeFmt.IsEnabled = false;
	  }
	  private int AddTabItem(String a_sHeader)
	  {
		TPDEDiagram diagram = new TPDEDiagram(m_Nodes);
		diagram.Saved = false;
		TPDETabItem tabItem = new TPDETabItem(diagram, "&#1053;&#1086;&#1074;&#1099;&#1081;");
		return m_MainTabCtrl.Items.Add(tabItem);
	  }
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: UserControl from Ruller with diagram
Reply #2 - Jan 25th, 2010 at 3:13pm
Print Post  
There isn't TPDETabItem in the version of the project you sent me, but the following code successfully shows new tabs when pressing File / New diagram -

Code
Select All
private void NewDgrm_Executed(object sender, ExecutedRoutedEventArgs e)
{
	m_MainTabCtrl.SelectedIndex = AddTabItem("xxx.tpd");
	TabItem tabItem = m_MainTabCtrl.Items[m_MainTabCtrl.SelectedIndex] as TabItem;
}
private int AddTabItem(String a_sHeader)
{
	TPDEDiagram diagram = new TPDEDiagram(m_Nodes);
	TabItem tabItem = new TabItem();
	tabItem.Content = diagram;
	return m_MainTabCtrl.Items.Add(tabItem);
} 

  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: UserControl from Ruller with diagram
Reply #3 - Jan 25th, 2010 at 3:23pm
Print Post  
Code
Select All
 /// <summary>
    /// Class represents the closeable tab item with TPDEDiagram object inside
    /// </summary>
    public class TPDETabItem: CloseableTabItem
    {
	  #region Data
	  private TPDEDiagram m_Diagram = null;
	  #endregion //Data

	  #region Constructors
	  /// <summary>
	  /// Default constructor
	  /// </summary>
	  /// <param name="a_Diagram">Diagram inside the tab item</param>
	  /// <param name="a_sHeader">Header of tab item</param>
	  public TPDETabItem(TPDEDiagram a_Diagram, String a_sHeader): base()
	  {
		m_Diagram = a_Diagram;
		Header = a_sHeader;
		Content = m_Diagram;
	  }
	  /// <summary>
	  /// Static constructor
	  /// </summary>
	  static TPDETabItem()
	  {
		DefaultStyleKeyProperty.OverrideMetadata(typeof(TPDEDiagram),
		    new FrameworkPropertyMetadata(typeof(TPDEDiagram)));
	  }
	  #endregion

	  #region Properties
	  /// <summary>
	  /// Gets diagram object
	  /// </summary>
	  public Diagram Diagram
	  {
		get { return m_Diagram.m_Diagram; }
		//set { m_Diagram.m_Diagram = value; }
	  }
	  #endregion //Properties
    }
 

  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: UserControl from Ruller with diagram
Reply #4 - Jan 25th, 2010 at 3:33pm
Print Post  
I found an error. Thanks!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint