示例#1
0
 protected override void OnInitialized(EventArgs e)
 {
     base.OnInitialized(e);
     Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
     {
         var presenter = VisualUtils.GetVisualChild <ContentPresenter>(this);
         _yesButton    = ContentTemplate?.FindName("PART_YesButton", presenter) as Button;
         _noButton     = ContentTemplate?.FindName("PART_NoButton", presenter) as Button;
         _okButton     = ContentTemplate?.FindName("PART_OKButton", presenter) as Button;
         _cancelButton = ContentTemplate?.FindName("PART_CancelButton", presenter) as Button;
         UpdateState();
     }));
 }
示例#2
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (!(Template.FindName(ContentHostTemplatePartName, this) is ContentControl contentControl))
            {
                throw new Exception("Error : The template set on this TreeViewItem does not have the mandatory \"PART_ContentHost\" template part.");
            }

            contentControl.EnsureLoaded(() =>
            {
                if (!(VisualTreeHelper.GetChild(contentControl, 0) is ContentPresenter contentPresenter))
                {
                    throw new Exception("Error : The content control template part of a TreeViewItem is expected to own a ContentPresenter.");
                }

                ContentElement = (ContentTemplate?.FindName(CustomContentHostTemplatePartName, contentPresenter)) as FrameworkElement ?? contentControl;
            });
        }