活动结束后如何获得通知(How to get notified after the event ends)

编程入门 行业动态 更新时间:2024-10-26 07:36:27
活动结束后如何获得通知(How to get notified after the event ends)

在我的UWP应用程序中,我使用CommandBar的 DynamicOverflowItemsChanging事件,我的用例不是很复杂,我尝试使用此事件解决另一个问题,请参阅本文的答案

因此,正如上面提供的链接中的答案所示,我试图调用此事件并同步MoreButton的可见性,现在问题是当命令栏的辅助溢出菜单没有删除项目或所以他们仍然显示他们在事件被解雇前已经拥有的物品,但是当这个事件完成时,物品的传输也完成了。

因此总之,我想以某种方式引发另一个事件,或者在DynamicOverflowItemsChanging完成其执行时收到通知,以便我可以获得正确的数据并正确设置更多按钮的可见性。 换句话说,我想实现DynamicOverflowItemsChanged事件的行为,这个事件不幸在api中不存在,所以我正在寻找一种替代方法。

我知道我可以在最后调用另一个事件(就在DynamicOverflowItemsChanging事件完成之前),但这样我仍然没有得到正确的值,只有在此事件完成时才能使用正确的值。 就像我们可以用Task.Then()做的那样,当一个任务完成时,另一个可以自动启动,所以我想在这里得到类似的东西。 任何建议,将不胜感激。

protected override void OnApplyTemplate() { var barr = (CommandBar)GetTemplateChild("MediaControlsCommandBar"); //the event to control the dynamicoverflow automatically. barr.DynamicOverflowItemsChanging += (s, e) => { if (_secondarycontrols.Items.Count == 0 && e.Action == CommandBarDynamicOverflowAction.AddingToOverflow) _moreButton.Visibility = Visibility.Visible; else if (_secondarycontrols.Items.Count == 1 && e.Action == CommandBarDynamicOverflowAction.RemovingFromOverflow) _moreButton.Visibility = Visibility.Collapsed; };//when this event finishes here I want to get notified. //base implementation base.OnApplyTemplate(); }

In my UWP app I am using DynamicOverflowItemsChanging event of a CommandBar my usecase is not very complex, I tried to solve another problem I had by using this event, see the answer of this post.

So as shown in the answer in the link I provided above, I am trying to invoke this event and sync the visibility of MoreButton now the problem is this event is fired when the secondary overflow menu of command bar doesn't have the item removed or added yet, so they still show the items which they had before the event was fired, but when this event is completed then transfer of items is also completed.

So in short I want to raise another event somehow or get notified when the DynamicOverflowItemsChanging completes its execution, so I can have the correct data and set the visibility of more button correctly. or in other words I want to implement a behaviour of DynamicOverflowItemsChanged event, which unfortunately doesn't exist in the api, so I am looking for an alternative way.

I know I can invoke another event right at the end (just before DynamicOverflowItemsChanging event is finished), but that way I still don't get the correct values, correct values only become available when this event finishes its execution. Like we can do with Task.Then() so when a task completes another can automatically start, so I want something like that here . any suggestions would be appreciated.

protected override void OnApplyTemplate() { var barr = (CommandBar)GetTemplateChild("MediaControlsCommandBar"); //the event to control the dynamicoverflow automatically. barr.DynamicOverflowItemsChanging += (s, e) => { if (_secondarycontrols.Items.Count == 0 && e.Action == CommandBarDynamicOverflowAction.AddingToOverflow) _moreButton.Visibility = Visibility.Visible; else if (_secondarycontrols.Items.Count == 1 && e.Action == CommandBarDynamicOverflowAction.RemovingFromOverflow) _moreButton.Visibility = Visibility.Collapsed; };//when this event finishes here I want to get notified. //base implementation base.OnApplyTemplate(); }

最满意答案

热烈的问候,微软学生合作伙伴:-)。

快速和肮脏的黑客会将一个Task.Delay添加到处理程序的末尾,并希望项目会改变,直到延迟结束。 这当然是非常丑陋和容易出错的。 我会建议一个不同的解决方案。

您已经可以访问CommandBarOverflowPresenter的_secondarycontrols 。 这是非常有用的,因为Items属性有一个VectorChanged事件,每当添加,删除或更改项目时都会触发该事件。 这意味着,您可以实际使用此事件并在其中移动您的逻辑,而不是使用DynamicOverflowItemsChanging事件。 然后您可以直接检查准确的物品数量。

Warm greetings, fellow Microsoft Student Partner :-) .

The quick and dirty hack would be to add a Task.Delay to the end of the handler and hope the items will have changed until the delay is over. This is of course really ugly and error prone. I would suggest a different solution.

You already have access to the _secondarycontrols which is a CommandBarOverflowPresenter. This is very useful, because Items property has a VectorChanged event which is fired whenever an item is added, removed or changed. This means, you can actually use this event and move your logic inside it instead of using the DynamicOverflowItemsChanging event. You can then directly check for the number of items which will be accurate.

更多推荐

本文发布于:2023-07-14 23:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1108341.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何获得   结束后   通知   ends   event

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!