简体   繁体   中英

Visibility of ViewBox set from code

On my Window, I have a ViewBox control, which contains a custom progress bar. 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.

When user clicks on the Login button, I need to show this ViewBox until Login is completed and collapse it again after success. But, when I (in code behind) set ViewBox.Visibility = Visible, it doesn't show up.

Can anybody tell me why, or how to fix it ?

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. 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. The login process has to be running in asynchronous manner, so the UI could draw my usercontrol.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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