WPF自适应窗体大小

WPF自适应窗体大小

  • Saturday, October 30, 2010 1:55 PM Dev.eloper
     
    0
    Sign In to Vote

    举例说明。windows的分辨率为1024*768的时候。我的WPF应用程序启动时的窗体大小为900*700。当windows的分辨率为1280*1024的时候。再次启动我的WPF程序时。窗体包括各个控件以及窗体的各个部位的文字、图片等都等比例放大。
    这个在winform中要自己写缩放代码。在WPF中如何能快速的实现该功能

Answers

  • Sunday, October 31, 2010 6:51 AM Yiling Lai
     
    0
    Sign In to Vote

    Hello

    Auto layout will be done by WPF automatically if your code is wrote correctly. Please take a look at wpf layout system. BTW, you can transfer you thread to CHS forum.

    http://msdn.microsoft.com/en-us/library/ms745058.aspx

    WPF能自动支持该项功能,只要你正确使用它的LAYOUT系统。你用中文提问最好转移到中文版的WPF论坛去。


    Keep improving.
    Yiling Lai. MVP (Visual C++ and Client App Dev)
    • Proposed As Answer byBob BaoMicrosoft, ModeratorMonday, November 01, 2010 9:14 AM
    • Marked As Answer byBob BaoMicrosoft, ModeratorTuesday, November 09, 2010 1:45 AM
    •  
  • Monday, November 01, 2010 9:14 AM Bob BaoMicrosoft, Moderator
     
    0
    Sign In to Vote

    Hi Dev.eloper,

    At first, I recommend you to translate this thread to English, that all community members on this forum can understand this question and help you. Or you could post it on the Chinese MSDN forum: http://social.msdn.microsoft.com/Forums/zh-CN/wpfzhchs/threads

    Then, regarding to this question, you would like to auto-match the screen size and auto-change the size of all controls. Yes, agree with Yiling Lai, WPF layout provides and supports it. WPF provides two panel: Grid and DockPanel can help you to achieve this goal.

    If you put any control in the Grid panel, and set the Margin property of the control to some value (please do not set the Height and Width properties, that will fix the size of the control). The control can match the size of the Grid and change to the different size when changing the Grid size. A simple sample, in a Grid, the Button and TextBlock can fill and match the Window size:

    <Window x:Class="WpfApplication12.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="350" Width="525">
     <Grid>
     <TextBlock Text="Hello World!" Margin="100,100,100,100"/>
     <Button Content="Button" Margin="100,120,100,100"/>
     Grid>
    Window>
    

    Please refer to the Layout in WPF: http://msdn.microsoft.com/en-us/library/ms745058.aspx Panels Overview: http://msdn.microsoft.com/en-us/library/ms754152.aspx  and a video http://windowsclient.net/learn/video.aspx?v=76354

    On the other hand, WPF does no support to change the font text automatically. But if we put the elements in the ViewBox with Stretch property to some value (like Uniform). The inner element can match the size of the ViewBox and the TextBlock can show the appropriate "font size":

     <Grid>
     <Viewbox Stretch="Uniform">
      <TextBlock Text="Hello World!"/>
     Viewbox>
     Grid>
    

    Sincerely,
    Bob Bao

     

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download all in one code framework !

     

    MSDN Subscriber Support in Forum 

    If you have any feedback on our support, please contact [email protected]

    • Marked As Answer byBob BaoMicrosoft, ModeratorTuesday, November 09, 2010 1:45 AM
    •  

All Replies

  • Saturday, October 30, 2010 10:08 PM Monir Sabbagh
     
    0
    Sign In to Vote

    请写英语

     

    That was: please write in English

     


     

    -

    • Edited byMonir Sabbagh Saturday, October 30, 2010 10:09 PMtranslation
    •  
  • Sunday, October 31, 2010 6:51 AM Yiling Lai
     
    0
    Sign In to Vote

    Hello

    Auto layout will be done by WPF automatically if your code is wrote correctly. Please take a look at wpf layout system. BTW, you can transfer you thread to CHS forum.

    http://msdn.microsoft.com/en-us/library/ms745058.aspx

    WPF能自动支持该项功能,只要你正确使用它的LAYOUT系统。你用中文提问最好转移到中文版的WPF论坛去。


    Keep improving.
    Yiling Lai. MVP (Visual C++ and Client App Dev)
    • Proposed As Answer byBob BaoMicrosoft, ModeratorMonday, November 01, 2010 9:14 AM
    • Marked As Answer byBob BaoMicrosoft, ModeratorTuesday, November 09, 2010 1:45 AM
    •  
  • Monday, November 01, 2010 9:14 AM Bob BaoMicrosoft, Moderator
     
    0
    Sign In to Vote

    Hi Dev.eloper,

    At first, I recommend you to translate this thread to English, that all community members on this forum can understand this question and help you. Or you could post it on the Chinese MSDN forum: http://social.msdn.microsoft.com/Forums/zh-CN/wpfzhchs/threads

    Then, regarding to this question, you would like to auto-match the screen size and auto-change the size of all controls. Yes, agree with Yiling Lai, WPF layout provides and supports it. WPF provides two panel: Grid and DockPanel can help you to achieve this goal.

    If you put any control in the Grid panel, and set the Margin property of the control to some value (please do not set the Height and Width properties, that will fix the size of the control). The control can match the size of the Grid and change to the different size when changing the Grid size. A simple sample, in a Grid, the Button and TextBlock can fill and match the Window size:

    <Window x:Class="WpfApplication12.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="350" Width="525">
     <Grid>
     <TextBlock Text="Hello World!" Margin="100,100,100,100"/>
     <Button Content="Button" Margin="100,120,100,100"/>
     Grid>
    Window>
    

    Please refer to the Layout in WPF: http://msdn.microsoft.com/en-us/library/ms745058.aspx Panels Overview: http://msdn.microsoft.com/en-us/library/ms754152.aspx  and a video http://windowsclient.net/learn/video.aspx?v=76354

    On the other hand, WPF does no support to change the font text automatically. But if we put the elements in the ViewBox with Stretch property to some value (like Uniform). The inner element can match the size of the ViewBox and the TextBlock can show the appropriate "font size":

     <Grid>
     <Viewbox Stretch="Uniform">
      <TextBlock Text="Hello World!"/>
     Viewbox>
     Grid>
    

    Sincerely,
    Bob Bao

     

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download all in one code framework !

     

    MSDN Subscriber Support in Forum 

    If you have any feedback on our support, please contact [email protected]

    • Marked As Answer byBob BaoMicrosoft, ModeratorTuesday, November 09, 2010 1:45 AM

你可能感兴趣的:(.net)