template control visibility

288 views Asked by At

In mui base project I declare a resource template control:

<ControlTemplate x:Key="loadingUserControlTemplate" TargetType="UserControl">
    <Grid x:Name="loadingContainer">
        <Border
                Opacity="0.5"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}">

            <ContentPresenter />
        </Border>
        <mui:ModernProgressRing x:Name="loadingAnimation"
                                IsActive="true" 
                                Width="80" 
                                Height="80" 
                                Style="{StaticResource WaveProgressRingStyle}" 
                                VerticalContentAlignment="Center" />
    </Grid>
</ControlTemplate>

and base class as user control:

public class LoadingUserControl : UserControl
{
    public bool _isLoading;

    public Boolean IsLoading
    {
        get { return _isLoading; }
        set
        {
            _isLoading = value;

            var loading = base.GetTemplateChild("loadingContainer") as Grid;

            if (loading != null)
            {
                if (value)
                {
                    base.IsEnabled = false;
                    loading.Visibility = Visibility.Visible;
                }

                else
                {
                    base.IsEnabled = true;
                    loading.Visibility = Visibility.Collapsed;
                }
            }
        }
    }
    public LoadingUserControl()
    {
        base.Template = (ControlTemplate)App.Current.FindResource("loadingUserControlTemplate");
    }
}

then problem is when I collapse my grid, collapsed parent grid! is it good idea? where is my mistake?

1

There are 1 answers

2
ZSH On

Use loading.Visibility = Visibility.Hidden; not collapse