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. Image for the cookie policy date
close icon

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

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;
}

1 Reply

RA Ranjitha Amirthalingam Syncfusion Team September 30, 2015 12:28 PM UTC

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.


Loader.
Live Chat Icon For mobile
Up arrow icon