入门

Window 下面只有一个Content ,比如Grid

 账号密码

        <Label Content="账号" HorizontalAlignment="Left" Margin="135,66,0,0" HorizontalContentAlignment="Right" VerticalAlignment="Top" Width="70"/>
        <TextBox Name="tbAccount" HorizontalAlignment="Left" Height="23" Margin="228,68,0,0" TextWrapping="NoWrap" Text="" VerticalAlignment="Top" Width="120"/>
        <Label Content="密码" HorizontalAlignment="Left" Margin="135,106,0,0" HorizontalContentAlignment="Right" VerticalAlignment="Top" Width="70"/>
        <PasswordBox Name="tbPwd" HorizontalAlignment="Left" Height="23" Margin="228,108,0,0" Password="123456" VerticalAlignment="Top" Width="120"/>

WPF 笔记 一 入门和 基本控件

 

WrapPanel

        Title="MainWindow" Height="450" Width="800">
    <WrapPanel >
        <Button>Test button 1</Button>
        <Button>Test button 2</Button>
        <Button>Test button 3</Button>
        <Button Height="40">Test button 4</Button>
        <Button>Test button 5</Button>
        <Button>Test button 6</Button>
    </WrapPanel>

面板以一行或者一列的形式来布置控件,当一行(列)放满之后自动转到下一行(列)

当WrapPanel使用水平方向时,基于最高的项,子控件将被赋予相同的高度。当WrapPanel是垂直方向时,基于最宽的项,子控件将被赋予相同的宽度。

 

Grid 中的MouseUp事件

    <Grid Name="Good" MouseUp="Good_MouseUp" Background="Transparent">
    </Grid>
        private void Good_MouseUp(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("HI");
        }

注意:xaml中的Background不可缺,否则无效。

 

资源

https://www.cnblogs.com/zty1294625258/p/6018928.html

例子一

        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <sys:String x:Key="strHelloWorld">Hello, world!</sys:String>
    </Window.Resources>
    <StackPanel Margin="10">
        <TextBlock Text="{StaticResource strHelloWorld}" FontSize="56" />
        <TextBlock>Just another "<TextBlock Text="{StaticResource strHelloWorld}" />" example, but with resources!</TextBlock>
    </StackPanel>
</Window>

WPF 笔记 一 入门和 基本控件

 

资源 下拉列表

          xmlns:sys="clr-namespace:System;assembly=mscorlib"

 <Window.Resources>
        <sys:String x:Key="ComboBoxTitle">Items:</sys:String>

        <x:Array x:Key="ComboBoxItems" Type="sys:String">
            <sys:String>Item #1</sys:String>
            <sys:String>Item #2</sys:String>
            <sys:String>Item #3</sys:String>
        </x:Array>

        <LinearGradientBrush x:Key="WindowBackgroundBrush">
            <GradientStop Offset="0" Color="Silver"/>
            <GradientStop Offset="1" Color="Gray"/>
        </LinearGradientBrush>
    </Window.Resources>
    <StackPanel Margin="10">
        <Label Content="{StaticResource ComboBoxTitle}" />
        <ComboBox ItemsSource="{StaticResource ComboBoxItems}" />
    </StackPanel>
View Code

相关文章:

  • 2021-05-27
  • 2022-01-15
  • 2022-02-22
  • 2021-11-17
  • 2022-01-10
  • 2021-10-10
  • 2021-10-26
猜你喜欢
  • 2022-02-03
  • 2021-05-23
  • 2021-07-20
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2021-12-22
相关资源
相似解决方案