private void ApplyingTemplate()
        {
            _hostContainer = GetTemplateChild(ButtonBaseConstants.ContentHostName) as Grid;
            _contentBody   = GetTemplateChild(ButtonBaseConstants.ContentBodyName) as FrameworkElement;

            ButtonBaseHelper.UpdateImageSource(_contentBody, _hostContainer, ImageSource, Stretch);
        }
Example #2
0
        public override void OnApplyTemplate()
#endif
        {
            _cancelButton.Content = ButtonBaseHelper.CreateXamlCancel(_cancelButton);

            base.OnApplyTemplate();
        }
        private void AppendCheck(object content)
        {
            if (!IsContentEmpty(content))
            {
                return;
            }

            Content = ButtonBaseHelper.CreateXamlCheck(this);
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            OpacityImageBrush = GetTemplateChild(ButtonBaseConstants.OpacityImageBrushName) as ImageBrush;
            var contentBody = GetTemplateChild(ButtonBaseConstants.ContentBodyName) as ContentControl;

            ButtonBaseHelper.ApplyTemplate(this, OpacityImageBrush, contentBody, Stretch, ImageSourceProperty);
        }
        private void UpdateImageSource()
        {
            var hostContainer         = GetTemplateChild(ButtonBaseConstants.ContentHostName) as Grid;
            var hostContainerDisabled = GetTemplateChild(ButtonBaseConstants.DisabledContentHostName) as Grid;

            var contentEnabled  = GetTemplateChild(ButtonBaseConstants.EnabledContentControlName) as FrameworkElement;
            var contentDisabled = GetTemplateChild(ButtonBaseConstants.DisabledContentControlName) as FrameworkElement;

            ButtonBaseHelper.UpdateImageSource(contentEnabled, hostContainer, ImageSource, Stretch);
            ButtonBaseHelper.UpdateImageSource(contentDisabled, hostContainerDisabled, ImageSource, Stretch);
        }
        private static void OnStretch(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            var sender = o as ToggleButtonBase;

            if (sender == null)
            {
                return;
            }

            ButtonBaseHelper.OnStretch(e, sender.OpacityImageBrush);
        }
        public override void OnApplyTemplate()
#endif
        {
            ApplyingTemplate();

            AppendCheck(Content);

            ButtonBaseHelper.ApplyForegroundToFillBinding(GetTemplateChild(ButtonBaseConstants.ContentBodyName) as ContentControl);
            ButtonBaseHelper.ApplyTitleOffset(GetTemplateChild(ButtonBaseConstants.ContentTitleName) as ContentControl);

            base.OnApplyTemplate();
        }
        public override void OnApplyTemplate()
#endif
        {
            base.OnApplyTemplate();

            ApplyingTemplate();

            AppendCheck(Content);

            IsEnabledStateChanged();

            ButtonBaseHelper.ApplyTitleOffset(GetTemplateChild(ButtonBaseConstants.ContentTitleName) as ContentControl);
        }
        private void IsEnabledStateChanged()
        {
            var contentBody    = GetTemplateChild(ButtonBaseConstants.ContentBodyName) as ContentControl;
            var enabledHolder  = GetTemplateChild(ButtonBaseConstants.EnabledHolderName) as Grid;
            var disabledHolder = GetTemplateChild(ButtonBaseConstants.DisabledHolderName) as Grid;

            if (contentBody != null && disabledHolder != null && enabledHolder != null)
            {
                if (!IsEnabled)
                {
                    enabledHolder.Children.Remove(contentBody);
                }
                else
                {
                    disabledHolder.Children.Remove(contentBody);
                }

                if (IsEnabled)
                {
                    if (!enabledHolder.Children.Contains(contentBody))
                    {
                        enabledHolder.Children.Insert(0, contentBody);
                    }
                }
                else
                {
                    if (!disabledHolder.Children.Contains(contentBody))
                    {
                        disabledHolder.Children.Insert(0, contentBody);
                    }
                }
            }

            UpdateLayout();

#if WINDOWS_STORE || WINDOWS_PHONE_APP
            if (ApplicationSpace.IsDesignMode)
            {
                ButtonBaseHelper.ApplyForegroundToFillBinding(contentBody);
            }
            else
            {
                Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => ButtonBaseHelper.ApplyForegroundToFillBinding(contentBody)).AsTask();
            }
#elif WINDOWS_PHONE
            //Dispatcher.BeginInvoke(() =>
            ButtonBaseHelper.ApplyForegroundToFillBinding(contentBody);
            //);
#endif
        }
        protected override void OnContentChanged(object oldContent, object newContent)
        {
            base.OnContentChanged(oldContent, newContent);

            if (oldContent == newContent)
            {
                return;
            }

            AppendCheck(Content);

            // content changed, wait a tick
#if WINDOWS_STORE || WINDOWS_PHONE_APP
            ButtonBaseHelper.ApplyForegroundToFillBinding(
                GetTemplateChild(ButtonBaseConstants.ContentBodyName) as ContentControl);
#elif WINDOWS_PHONE
            Dispatcher.BeginInvoke(() =>
                                   ButtonBaseHelper.ApplyForegroundToFillBinding(
                                       GetTemplateChild(ButtonBaseConstants.ContentBodyName) as ContentControl));
#endif
        }
 private void UpdateImageSource()
 {
     ButtonBaseHelper.UpdateImageSource(_contentBody, _hostContainer, ImageSource, Stretch);
 }