开发者

How to accomplish different states of view in WPF Apps

开发者 https://www.devze.com 2023-03-30 05:41 出处:网络
I have an idea for a personal project. And I know one way of accomplishing it in Windows Forms (which I no longer wish to use). Basically I could (in WinForms) just draw everything onto the screen (Fo

I have an idea for a personal project. And I know one way of accomplishing it in Windows Forms (which I no longer wish to use). Basically I could (in WinForms) just draw everything onto the screen (Form) and then when I need to switch views/states of the application, just redraw the new stuff in the old stuff's place.

But how can we have different states in WPF? Is there a "right" or "proper" way of doing this? Is something like this covered somewhere in the docs?

I'd like to d开发者_JS百科o my own searching, but I have no idea what exactly to look for, and current attempts at finding the right information, so far have yielded no helpful (or even relevant) results.

Any help at all will be greatly appreciated. I am new to WPF, but have been making a lot of progress this past week!

Thank you!

P.S.: I just thouhght of something. If the solution was to draw what is needed for one screen, and when it is time to display the next screen, just dispose of/hide everything and create/display the new stuff, then how would we get around this? Because we can't/shouldn't change XAML markup at runtime, can/should we? :/


Not sure how you drawn your views/states in WinForms (direct painting on a Graphics object?).

The closest to what you're describing is the VisualStateManager. You can use it to statically define several visual states inside a single XAML and transit between them (using a smooth animation if you want).

If what you've done was show different Forms with Show/ShowDialog(), then the equivalent would be to use different Windows and Show/Hide them.

If you just cleared/added Controls to your form, then you can do just the same in WPF. Most Controls in WPF have a Content or Children property instead of Control.Controls in Forms.


I don't know if I understand what you really want. But here are my thoughts:

  • You can use several Windows and Show/Hide them accordingly
  • You can use the Frame/Page functionality in WP (MSDN)
  • if you really need to you could load your XAML and remove the topmost content in your Window and replace it with the loaded content
  • You could use the VisualStateGroup functionality to change the appearance of your current window

I think you will be happy with the second solution

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号