Exemple #1
0
 private void OnWhenChanged(bool value)
 {
     if (value)
     {
         if (ContentTemplate != null)
         {
             _element = ContentTemplate.GetElement(new ElementFactoryGetArgs
             {
                 Data   = Content,
                 Parent = this
             });
             if (_element is FrameworkElement element && element.DataContext != Content)
             {
                 element.DataContext = Content;
             }
             Children.Add(_element);
         }
     }
     else
     {
         if (ContentTemplate != null && _element != null)
         {
             ContentTemplate.RecycleElement(new ElementFactoryRecycleArgs
             {
                 Element = _element,
                 Parent  = this
             });
             _element = null;
         }
         Children.Clear();
     }
 }