views:

686

answers:

1

Hello, I'm creating a Loading Adorner that has a swirling icon over it. I tried binding the visibility property directly in the XAML but that actually hides everything inside its hierarchy.

I have this in my XAML:

<AdornerDecorator Visibility="{Binding Path=RootGroup.Loading, Converter={StaticResource VisibilityConverter}}">
    <TreeView x:Name="groupTreeView" />
</AdornerDecorator>

and this in my constructor

LoadingAdorner adorner = new LoadingAdorner(groupTreeView);
AdornerLayer.GetAdornerLayer(groupTreeView).Add(adorner);

This isn't want I wanted so I tried binding it in the code instead:

LoadingAdorner adorner = new LoadingAdorner(groupTreeView);
Binding bind = new Binding("RootGroup.Loading");
bind.Source = this.DataContext;
bind.Converter = new VisibilityConverter();
adorner.SetBinding(LoadingAdorner.VisibilityProperty, bind);
AdornerLayer.GetAdornerLayer(groupTreeView).Add(adorner);

This will work if the DataContext is not null because it can actually find RootGroup.Loading. But if it is null then the binding has no source to look at.

So I was wondering what does the XAML databinding use as its .Source ? Binding directly in the XAML binds to the correct property, but it doesn't achieve the same result. So I'm just wondering what I should be setting my .Source to So i can bind to RootGroup.Loading ?

Thanks, Raul

A: 

This doesn't directly answer your question, but why are you using an adorner to get the loading animation effect.

Why not just use a border element that is a sibling of your TreeView that is Z-Ordered on top and then do your animation in that.

So you do something like this

<Grid>    
  <TreeView />
  <Border x:Name="myBorder">... </Border>      
</Grid>

Then you can do all your binding in XAML without hiding the entire Visual Tree.

Foovanadil
Well as you said it doesn't answer the question directly... but your approach is better when what I was doing.Thanks a lot!
HaxElit