This is a migrated thread and some comments may be shown as answers.

BusyContentTemplate ContentPresenter Margin

3 Answers 190 Views
BusyIndicator
This is a migrated thread and some comments may be shown as answers.
Ville
Top achievements
Rank 1
Ville asked on 21 Apr 2020, 09:08 AM

Hi,

i'm using RadBusyIndicator to show "sub views" in our applications main window as BusyContent using BusyContentTemplate and it works.

The problem that i'm having is that the content presenter has locally assigned margin value that i haven't succeeded to override.

What i've tried?

1.) Tried to override the margin with implicit style in resources of RadBusyIndicator with no luck (not also preferred method because of all child content presenters get affected)

2.) Wrote a new custom control that derives from RadBusyIndicator and gave it a "NewMargin" dependency property of type Thickness. When the value of "NewMargin" changes i use VisualTreeHelpers to get the content presenter from visual tree and assing the new value to content presenter, but somehow it doesn't work either. The value gets set but the the view doesn't reflect the change.

The derived indicator:

    public class AdaBusyIndicator : RadBusyIndicator
    {
        public static readonly DependencyProperty NewMarginProperty =
          DependencyProperty.Register("NewMargin", typeof(Thickness),
        typeof(AdaBusyIndicator), new UIPropertyMetadata(new Thickness(), NewMarginPropertyChanged));

        private static void NewMarginPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is AdaBusyIndicator abi && VisualTreeHelpers.FindChild<Border>(abi, "Indicator") is Border brd &&
                VisualTreeHelpers.FindChild<ContentPresenter>(brd) is ContentPresenter cpres && e.NewValue is Thickness newThickness)
            {
                Thickness thickness = new Thickness(newThickness.Left, newThickness.Top, newThickness.Right, newThickness.Bottom);

                cpres.Margin = thickness;
            }
        }

        public Thickness NewMargin
        {
            get
            {
                return (Thickness)GetValue(NewMarginProperty);
            }
            set
            {
                SetValue(NewMarginProperty, value);
            }
        }
    }

 

3 Answers, 1 is accepted

Sort by
0
Vicky
Telerik team
answered on 23 Apr 2020, 06:44 AM

Hello Ville,

Thanks for the provided resources and information.

There is no need of custom (derived) BusyIndicator to achieve the desired result. The template structure of the control includes a ContentPresenter, which for some of the Telerik themes, has a hard-coded default margin. Could you please tell me which is the preferred theme for your application?

In the meantime, you can try the following suggestions:

  • play with the padding of the BusyIndicator control;
  • add margin to some of the elements inside the custom BusyContentTemplate;
  • edit the default template of the BusyIndicator and override the margin of the ContentPresenter;

For any of the first two options, you can look at the following code snippet and sample image as a reference:

<telerik:RadBusyIndicator IsBusy="True" Background="LimeGreen" Padding="20">
    <telerik:RadBusyIndicator.BusyContentTemplate>
        <DataTemplate>
            <Grid Background="Lime">
                <TextBlock Text="Custom Busy Content" Margin="20" VerticalAlignment="Center" HorizontalAlignment="Center"/>
            </Grid>
        </DataTemplate>
    </telerik:RadBusyIndicator.BusyContentTemplate>
    <Grid Background="Green">
        <TextBlock Text="Loaded Content" VerticalAlignment="Center" HorizontalAlignment="Center"/>
    </Grid>
</telerik:RadBusyIndicator>

Best Regards,
Vicky
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Ville
Top achievements
Rank 1
answered on 23 Apr 2020, 10:14 AM

Thanks for your reply & suggestions Vicky.

We are using the default theme.

I think i'll try editing the default template as described and reply here if the problem persists.

br. Ville

 

 

0
Vicky
Telerik team
answered on 24 Apr 2020, 11:08 AM

Hi Ville,

Please, take as much time as you need.

I remain at your disposal for any further assistance you may need.

Best Regards,
Vicky
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
BusyIndicator
Asked by
Ville
Top achievements
Rank 1
Answers by
Vicky
Telerik team
Ville
Top achievements
Rank 1
Share this question
or