简体   繁体   English

缩放视图框内所有控件的高度和宽度

[英]Scale height and width of all control inside viewbox

I am new to WPF.我是 WPF 的新手。 In my code i have a simple WPF window with a few controls.在我的代码中,我有一个带有几个控件的简单 WPF 窗口。 All the controls are contained in the View Box.所有控件都包含在视图框中。 My problem is that when i resize the the window, the control size text is not resizing proportionately.我的问题是,当我调整窗口大小时,控件大小文本没有按比例调整大小。 Here is my code:这是我的代码:

<Window x:Class="DesktopGoogleReader.UIelements.About"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="About" Height="346" Width="435"
    >
    <Window.Background>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,0.5">
            <LinearGradientBrush.GradientStops>
                <GradientStop Offset="0" Color="#eee" />
                <GradientStop Offset="1" Color="#ccc" />
            </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>
    </Window.Background>
    <Viewbox Stretch="Uniform">
        <Grid>        
            <Label Height="41" Margin="83,12,12,0" Name="label1" VerticalAlignment="Top" FontSize="20" FontWeight="Bold">Desktop Google Reader</Label>
            <Image Margin="348,0,0,0" Name="image1" Stretch="Fill" Height="65" HorizontalAlignment="Left" VerticalAlignment="Top" Width="65" Source="C:\Users\TRIDIP\Desktop\tmp\Desktop Google Reader WPF good UI\trunk\DesktopGoogleReader\DesktopGoogleReader.ico" />
            <Label Height="28" Margin="92,49,12,0" Name="label_versionName" VerticalAlignment="Top">Version: Versionnumber</Label>
            <TextBlock Margin="12,83,12,0" Name="textBlock1" Height="54" VerticalAlignment="Top" Text="Desktop Google Reader is Windows / .NET based client to the RSS aggregation service Google Reader. It is licensed under the New BSD License (BSD). It is developed by Konstantins Onufrijevs and Sven Walther" TextWrapping="Wrap" />
            <Label Margin="12,134,12,0" Name="label2" Height="29" VerticalAlignment="Top">Credits: Desktop Google Reader uses the following external resources:</Label>
            <Button HorizontalAlignment="Left" Margin="12,161,0,0" Name="button_snarlChsarp" Width="173" Height="23" VerticalAlignment="Top" >Snarl Connector</Button>
            <Button Margin="191,161,0,0" Name="button_TweetSharp" Height="23" VerticalAlignment="Top" HorizontalAlignment="Left" Width="173" >TweetSharp</Button>
            <Button Height="23" HorizontalAlignment="Left" Margin="12,190,0,0" Name="button_iconSet" VerticalAlignment="Top" Width="173" >Function Icon Set</Button>
            <Button Height="23" Margin="191,190,0,0" Name="button_facebook" VerticalAlignment="Top" HorizontalAlignment="Left" Width="173" >Facebook Developer Toolkit</Button>
            <Button Height="23" HorizontalAlignment="Left" Margin="12,219,0,0" Name="button_awesomium" VerticalAlignment="Top" Width="173" >Web Kit .NET</Button>
            <Button Height="23" Margin="191,219,0,0" Name="button_winkle" VerticalAlignment="Top" HorizontalAlignment="Left" Width="173" >Winkle Update System</Button>
            <TextBlock Height="59" Margin="12,248,12,0" Name="textBlock_contributors" VerticalAlignment="Top" Text="Contributors: We want to thank all the people using Desktop Google Reader. A special thanks goes to Henry C. for his continues help in improving and supporting our project." TextAlignment="Left" TextWrapping="Wrap" />
        </Grid>
    </Viewbox>
</Window>

Need to modify the Stretch.需要修改Stretch。

Uniform will keep the text proportional.统一将保持文本成比例。
You are probably looking for Fill.您可能正在寻找填充。

Stretch Enumeration 拉伸枚举

Don't set the height and widths of a control it is not going to resize.不要设置不会调整大小的控件的高度和宽度。
And put the Viewbox in the Grid (not Grid in the Viewbox).并将 Viewbox 放在 Grid 中(而不是 Viewbox 中的 Grid)。

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Viewbox Grid.Row="0" Grid.Column="0" Stretch="Fill">
        <TextBox Text="size me" TextChanged="TextBox_TextChanged" />
    </Viewbox>
    <Viewbox Grid.Row="1" Grid.Column="0" Stretch="Fill">
        <TextBox Text="size me to0 " TextChanged="TextBox_TextChanged" />
    </Viewbox>
</Grid>

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

相关问题 为Windows窗体控件提供百分比宽度/高度 - Give Windows Form control a percentage width/height 从ViewBox拉伸中豁免AdornerLayer中的控件 - Exempt control in AdornerLayer from ViewBox stretching 绑定错误将空值绑定到wpf控件的宽度和高度 - Binding errors While Binding null values to Width and Height of the wpf control 如何在没有视框的情况下缩放具有保持纵横比和位置的控件? - How to scale controls with maintained aspect ratio and position without viewbox? 在Viewbox中获取TextBlock / Label以进行缩放而不会产生不希望的填充 - Getting a TextBlock/Label in Viewbox to Scale without undesirable padding 控件的边界与设置控件的X,Y,Width,Height有什么区别? - What is the difference between control's bounds and setting X,Y,Width,Height of a control? 如何利用ViewBox控件来调整应用程序的大小? - How to make use of the ViewBox control to make the application re-sizable? 高度和宽度的绝对值 - Absolute values of height and width 在椭圆周长上找到一个点,该点位于具有中心点,高度和宽度的矩形内? - finding a point on an ellipse circumference which is inside a rectangle having center point, height and width? 如何使视图模型的属性设置所有关联子控件的高度/宽度 - How to have a property of a view model set the height/width for all associate child controls
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM