We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

[Bug] ISymbol overwrites Content and ContentTemplate in NodeViewModel after ItemAdded event

Thread ID:

Created:

Updated:

Platform:

Replies:

120639 Sep 29,2015 02:25 PM Sep 30,2015 08:28 AM WPF 1
loading
Tags: SfDiagram
Steven Brodhead
Asked On September 29, 2015 02:25 PM

If you set Content and ContentTemplate on a NodeViewModel in the ItemAdded event handler after a symbol item is dragged in from the stencil, the values in the associated ISymbol overwrite Content and ContentTemplate some time after the event handler is called. These should probably be initialized from the ISymbol object's data BEFORE the event is fired.
A workaround is to have an isInitialized flag and set the content and template on the subsequent ItemTapped event, which is called when the user released the mouse button, but this is probably not the intended procedure.
voidCanvasItemAdded(objectsender,ItemAddedEventArgsargs)
{
varitem=args.ItemasNodeViewModel;
item.Content=myContent;//Thesegetoverwritten!
item.ContentTemplate=myTemplate;
}

Ranjitha Amirthalingam [Syncfusion]
Replied On September 30, 2015 08:28 AM

Hi Steven,

Thanks for contacting Syncfusion Support.

We have achieved your requirement “Need to set ContentTemplate to the dropped Node”. SymbolTemplate of ISymbol is applied to ContentTemplate of the droppedNode once droppedNode is added into the Page (ItemAdded event completed). So, SymbolTemplate will be overrided if we set ContentTemplate to the droppedNode in the ItemAdded event. So, ContentTemplate to droppedNode is set after SymbolTemplate is applied. We have provided sample and code example to represent this. Please refer to the sample and code example as below .

Code example:

void MainWindow_ItemAdded(object sender, ItemAddedEventArgs args)

        {

            if (args.ItemSource == ItemSource.Stencil)

            {

                var dropedItem = args.Item as INode;


                if (dropedItem != null)

                {                   

                    dropedItem.PropertyChanged += dropedItem_PropertyChanged;

                }


            }


        }


        void dropedItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)

        {

            if (e.PropertyName.Equals("ContentTemplate"))

            {

                (sender as INode).PropertyChanged -= dropedItem_PropertyChanged;

                (sender as INode).ContentTemplate = this.Resources["nodetemplate"] as DataTemplate;

            }
        }


XAML:

       <DataTemplate x:Key="nodetemplate">

            <Grid>

                <Button Content="mycontent" Width="80" Height="50"/>

            </Grid>
        </DataTemplate>


Sample Link: DropNodeCntntTmplte



Regards,
Ranjitha A.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;