WPF Adorner 可见性数据以编程方式绑定
我正在创建一个加载装饰器,上面有一个旋转图标。我尝试直接在 XAML 中绑定可见性属性,但这实际上隐藏了其层次结构内的所有内容。
我的 XAML 中有这个:
<AdornerDecorator Visibility="{Binding Path=RootGroup.Loading, Converter={StaticResource VisibilityConverter}}">
<TreeView x:Name="groupTreeView" />
</AdornerDecorator>
在我的构造函数中有这个
LoadingAdorner adorner = new LoadingAdorner(groupTreeView);
AdornerLayer.GetAdornerLayer(groupTreeView).Add(adorner);
这不是我想要的,所以我尝试将它绑定在代码中:
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);
如果 DataContext 不为空,这将起作用,因为它实际上可以找到 RootGroup.Loading。但如果它为 null,则绑定没有可查看的源。
所以我想知道 XAML 数据绑定使用什么作为其 .Source ?直接在 XAML 中绑定会绑定到正确的属性,但不会达到相同的结果。所以我只是想知道我应该将 .Source 设置为什么以便我可以绑定到 RootGroup.Loading ?
谢谢, 劳尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不能直接回答您的问题,但为什么要使用装饰器来获得加载动画效果。
为什么不只使用一个边框元素,它是 TreeView 的同级元素,在顶部按 Z 顺序排列,然后在其中执行动画。
所以你可以这样做,
然后你可以在 XAML 中完成所有绑定,而无需隐藏整个可视化树。
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
Then you can do all your binding in XAML without hiding the entire Visual Tree.