WPF自适应窗体大小

WPF自适应窗体大小

  • Saturday, October 30, 2010 1:55 PM Dev.eloper Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

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

Answers

  • Sunday, October 31, 2010 6:51 AM Yiling Lai Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
      Answer

    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)
  • Monday, November 01, 2010 9:14 AM Bob BaoMicrosoft, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
      Answer Has Code

    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 msdnmg@microsoft.com

All Replies

  • Saturday, October 30, 2010 10:08 PM Monir Sabbagh Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    请写英语

     

    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 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
      Answer

    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)
  • Monday, November 01, 2010 9:14 AM Bob BaoMicrosoft, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
      Answer Has Code

    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 msdnmg@microsoft.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值