StackPanel2深入理解

This commit is contained in:
Bunny 2024-12-30 11:10:50 +08:00
parent fea3514def
commit ca5293331c
7 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,9 @@
<Application x:Class="WPF基础_2_StackPanel2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF基础_2_StackPanel2"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -0,0 +1,12 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace WPF基础_2_StackPanel2;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

View File

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@ -0,0 +1,24 @@
<Window x:Class="WPF基础_2_StackPanel2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel Margin="3">
<Label Margin="3" HorizontalAlignment="Center">垂直排放居中所有按钮margin3</Label>
<Button Margin="3" MaxWidth="200" MinWidth="100">最大宽度200最小宽度100 1</Button>
<Button Margin="3" MaxWidth="200" MinWidth="100">最大宽度200最小宽度100 2</Button>
<Button Margin="3" MaxWidth="200" MinWidth="100">最大宽度200最小宽度100 3</Button>
<Button Margin="3" MaxWidth="200" MinWidth="100">最大宽度200最小宽度100 4</Button>
<TextBox AcceptsReturn="True" MaxWidth="400" MinWidth="100" TextWrapping="Wrap" >
1. 每个按钮尺寸不能小于最小尺寸
2. 每个按钮尺寸不能超过最大尺寸(除非执行错误操作,使最大尺寸比最小尺寸还小)
3. 如果最小尺寸大于 &lt;StackPanel&gt; 宽度会被剪裁
4. 水平尺寸,默认 HorizontalAlignment设置为Stretch 所以 &lt;StackPanel&gt; 将尝试放大按钮以沾满面板整个宽度
</TextBox>
<TextBlock />
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,23 @@
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WPF基础_2_StackPanel2;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>WPF基础_2_StackPanel2</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>

View File

@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF基础-1-2-和xaml一起
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF基础-2-StackPanel", "WPF基础-2-StackPanel\WPF基础-2-StackPanel.csproj", "{0BF66DA6-EDC2-41D2-8D92-ABF4383B8DFB}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF基础-2-StackPanel", "WPF基础-2-StackPanel\WPF基础-2-StackPanel.csproj", "{0BF66DA6-EDC2-41D2-8D92-ABF4383B8DFB}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF基础-2-StackPanel2", "WPF基础-2-StackPanel2\WPF基础-2-StackPanel2.csproj", "{1D149BDE-58BF-4E85-8AC2-A689FE3E5E4D}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -36,5 +38,9 @@ Global
{0BF66DA6-EDC2-41D2-8D92-ABF4383B8DFB}.Debug|Any CPU.Build.0 = Debug|Any CPU {0BF66DA6-EDC2-41D2-8D92-ABF4383B8DFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BF66DA6-EDC2-41D2-8D92-ABF4383B8DFB}.Release|Any CPU.ActiveCfg = Release|Any CPU {0BF66DA6-EDC2-41D2-8D92-ABF4383B8DFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BF66DA6-EDC2-41D2-8D92-ABF4383B8DFB}.Release|Any CPU.Build.0 = Release|Any CPU {0BF66DA6-EDC2-41D2-8D92-ABF4383B8DFB}.Release|Any CPU.Build.0 = Release|Any CPU
{1D149BDE-58BF-4E85-8AC2-A689FE3E5E4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D149BDE-58BF-4E85-8AC2-A689FE3E5E4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D149BDE-58BF-4E85-8AC2-A689FE3E5E4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D149BDE-58BF-4E85-8AC2-A689FE3E5E4D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal