none
Popup的Opened事件触发一次就再也不能触发了 RRS feed

  • 问题

  • <Popup HorizontalAlignment="Stretch" x:Name="popup_tips" Grid.ColumnSpan="3" IsOpen="{Binding Popup_IsOpen}" Opened="popup_tips_Opened" Closed="popup_tips_Closed"> <Grid Height="40" x:Name="grid_tips" Background="#8bc34a" VerticalAlignment="Top" Width="{Binding ActualWidth,ElementName=popup_tips}"> <TextBlock Grid.Row="1" x:Name="tbk_tips" TextWrapping="Wrap" FontSize="20" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Popup_Text}"/> </Grid> <Popup.ChildTransitions> <TransitionCollection> <EdgeUIThemeTransition Edge="Top" /> </TransitionCollection> </Popup.ChildTransitions> </Popup>

    下面还有个按钮绑定Command触发IsOpen值变化,但是第一次IsOpen变为True时,Opened触发了,然后IsOpen变为False,我再按一次按钮,Opened就再也没触发了

    2015年8月6日 9:58

答案

  • Hello DandelionI,

    >>下面还有个按钮绑定Command触发IsOpen值变化,但是第一次IsOpen变为True,Opened触发了,然后IsOpen变为False,我再按一次按钮,Opened就再也没触发了

    因为不知道你是如何写你的按钮绑定command,我用一个button click时间来简单代替了一下然后代码成这样:

    private void popup_tips_Opened(object sender, object e){}

    private void popup_tips_Closed(object sender, object e){}

    private void Button_Click(object sender, RoutedEventArgs e) {

    if (popup_tips.IsOpen) { popup_tips.IsOpen = false; } else {

    popup_tips.IsOpen = true; } }


    openclose时间上分别添加一个断点后发现这两时间是每次都会触发的。所以我猜测问题是你后台对于IsOpen的属性更改没有通知到前台,如果可以的话你可以把你的command绑定命令也一起给我们看下。或者用button click事件代替。

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2015年8月7日 2:22
    版主

全部回复

  • Hello DandelionI,

    >>下面还有个按钮绑定Command触发IsOpen值变化,但是第一次IsOpen变为True,Opened触发了,然后IsOpen变为False,我再按一次按钮,Opened就再也没触发了

    因为不知道你是如何写你的按钮绑定command,我用一个button click时间来简单代替了一下然后代码成这样:

    private void popup_tips_Opened(object sender, object e){}

    private void popup_tips_Closed(object sender, object e){}

    private void Button_Click(object sender, RoutedEventArgs e) {

    if (popup_tips.IsOpen) { popup_tips.IsOpen = false; } else {

    popup_tips.IsOpen = true; } }


    openclose时间上分别添加一个断点后发现这两时间是每次都会触发的。所以我猜测问题是你后台对于IsOpen的属性更改没有通知到前台,如果可以的话你可以把你的command绑定命令也一起给我们看下。或者用button click事件代替。

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2015年8月7日 2:22
    版主
  • public DelegateCommand LoginCommand { get; set; }
    
    LoginCommand = new DelegateCommand(Login);
    
    private async void Login()
            {
                Popup_IsOpen = true;
            }
    
    private bool _Popup_IsOpen;
            public bool Popup_IsOpen
            {
                get { return _Popup_IsOpen; }
                set { this.SetProperty(ref this._Popup_IsOpen, value); }
            }
    
    这是我在ViewModel里面写的,但是Opened就是无法触发第二次

    2015年8月7日 8:15
  • 非常感谢您的帮助,我发现是因为IsOpen的绑定Mode没有设置为TwoWay导致ViewModel里的属性值没有改变
    2015年8月7日 8:22