简体   繁体   English

通过代码设置ViewBox的可见性

[英]Visibility of ViewBox set from code

On my Window, I have a ViewBox control, which contains a custom progress bar. 在我的Window上,我有一个ViewBox控件,其中包含一个自定义进度栏。 I set its Visibility to Collapsed in design mode, because I need to display it in only certain moment (during login into app). 在设计模式下,我将其“可见性”设置为“已折叠”,因为我只需要在特定时间(登录应用程序期间)显示它。

In my progress bar, which is usercontrol, I have event handler for VisibilityChanged event where I stop and start my animation. 在我的进度条(即用户控件)中,我具有VisibilityChanged事件的事件处理程序,在其中停止并开始动画。

When user clicks on the Login button, I need to show this ViewBox until Login is completed and collapse it again after success. 当用户单击“登录”按钮时,我需要显示此ViewBox,直到“登录”完成,然后在成功后再次将其折叠。 But, when I (in code behind) set ViewBox.Visibility = Visible, it doesn't show up. 但是,当我(在后面的代码中)设置ViewBox.Visibility = Visible时,它没有显示。

Can anybody tell me why, or how to fix it ? 谁能告诉我原因,或如何解决?

XAML: XAML:

    <Viewbox x:Name="cpProgress" Width="50" Height="50" HorizontalAlignment="Center"   VerticalAlignment="Bottom" Grid.Row="1" Visibility="Collapsed" >
        <lc:CircularProgress />             
    </Viewbox>

Thanks 谢谢

ViewBox.Visibility = Visible更改为cpProgress.Visibility = Visible并确保Grid具有为第1行定义的正确行高。

I've finally come to solution of this problem. 我终于来解决这个问题了。 It is really simple :). 这真的很简单:)。 I've just forgot that If I run the login process in same thread, as my window is in, the UI will hang until the login is completed. 我只是忘记了,如果我在窗口所在的同一个线程中运行登录过程,则UI将挂起,直到登录完成。 So solution is to spawn a new thread,run the login in its context and wait for completed flag to be set in UI's thread. 因此,解决方案是生成一个新线程,在其上下文中运行登录并等待在UI线程中设置completed标志。 The login process has to be running in asynchronous manner, so the UI could draw my usercontrol. 登录过程必须以异步方式运行,因此UI可以绘制我的usercontrol。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM