• C#基础:WPF中常见控件的布局基础


    一、用ViewBox实现放缩控件不变

    二、布局代码

    1. <Window x:Class="WpfApp1.MainWindow"
    2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4. Title="MainWindow" Height="316" Width="778">
    5. <Viewbox Stretch="Fill">
    6. <Grid>
    7. <Grid.ColumnDefinitions>
    8. <ColumnDefinition Width="4*"/>
    9. <ColumnDefinition Width="293*"/>
    10. Grid.ColumnDefinitions>
    11. <Grid Grid.Column="0" >
    12. <Grid.RowDefinitions>
    13. <RowDefinition Height="1*"/>
    14. <RowDefinition Height="1*"/>
    15. <RowDefinition Height="1*"/>
    16. <RowDefinition Height="1*"/>
    17. <RowDefinition Height="1*"/>
    18. Grid.RowDefinitions>
    19. <Label Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center">LabelLabel>
    20. <Button Grid.Row="1" Margin="3">Button 1Button>
    21. <Button Grid.Row="2" Margin="3">Button 2Button>
    22. <Button Grid.Row="3" Margin="3">Button 3Button>
    23. <Button Grid.Row="4" Margin="3">Button 4Button>
    24. Grid>
    25. <Grid Grid.Column="1">
    26. <Grid.RowDefinitions>
    27. <RowDefinition Height="1*"/>
    28. <RowDefinition Height="1*"/>
    29. Grid.RowDefinitions>
    30. <Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Top" Width="388" Height="50" Grid.RowSpan="2">
    31. <Grid.RowDefinitions>
    32. <RowDefinition Height="3*"/>
    33. <RowDefinition Height="5*"/>
    34. Grid.RowDefinitions>
    35. <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,24" Grid.RowSpan="2">
    36. <Label Height="27">标签1Label>
    37. <TextBox Margin="5" VerticalAlignment="Center" HorizontalAlignment="Stretch" Width="Auto" Text="Search 1"/>
    38. <Label Height="25">标签2Label>
    39. <TextBox Margin="5" VerticalAlignment="Center" HorizontalAlignment="Stretch" Width="Auto" Text="Search 2"/>
    40. StackPanel>
    41. <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="2,7,2,0">
    42. <Label Height="25">标签3Label>
    43. <ComboBox Margin="5" VerticalAlignment="Center" Width="59">
    44. <ComboBoxItem Content="Option 1"/>
    45. <ComboBoxItem Content="Option 2"/>
    46. <ComboBoxItem Content="Option 3"/>
    47. ComboBox>
    48. <Label Height="26">标签4Label>
    49. <CheckBox Margin="3" VerticalAlignment="Center" Content="Checkbox" FontSize="10" HorizontalContentAlignment="Left" VerticalContentAlignment="Center"/>
    50. <Button Margin="30 5 5 5" VerticalAlignment="Center" Content="Search" FontSize="10"/>
    51. StackPanel>
    52. Grid>
    53. <DataGrid Grid.Row="1" Margin="5,20,5,0" Height="70" VerticalAlignment="Top">
    54. DataGrid>
    55. Grid>
    56. Grid>
    57. Viewbox>
    58. Window>

    三、布局设计思路

  • 相关阅读:
    LeetCode 面试题 08.11. 硬币
    采集数据重复解决方法
    H5语音合成播放
    Qt(C++)面试题 | 精选25项常问
    1、基本概念
    爬虫之Scrapy框架
    论文写作系列1:如何回复中文审稿意见
    [python数据处理系列] 深入理解与实践:用Python进行主成分分析(PCA)
    ClickHouse(17)ClickHouse集成JDBC表引擎详细解析
    ​力扣解法汇总1413-逐步求和得到正数的最小值
  • 原文地址:https://blog.csdn.net/m0_67412019/article/details/138167286