• 控件(转)


    一、命令控件(包括Button、RepeatButton、HyperLinkButton)

    • Button:

      <Button x:Name="MyButton1" Height="20" Width="50" Margin="0,0,0,0" Click="MyButton1_Click" ClickMode="Release">

      <Button.Content>

      我的按钮

      </Button.Content>

      </Button>

      • X:Name 为Button控件的名称。
      • Height,Width 为控件的高度和宽度。
      • Margin 可以理解为外留空Click为触发click事件要执行的过程。
      • ClickMode为Click事件的触发模式包括Release(释放鼠标时触发,为默认设置)、Press(按下鼠标时触发)、Hover(鼠标悬停时触发)。
      • Button是一个内容控件,可以使用Content属性定制内容,简单的文字内容可以使用 Content来定义,如果要显示图片或视频等其他内容通过 <Button.Content></Button.Content来定义例如

        <Button.Content>

            <Image Source="App.png"/>

    </Button.Content>

    • RepeatButton:

      <RepeatButton x:Name="MyRepeatButton" Margin="128,129,113,140" Click="MyRepeatButton_Click" ClickMode="Release" Delay="1000" Interval="250">

      <RepeatButton.Content>

      <TextBlock x:Name="MyBlock"></TextBlock>

      </RepeatButton.Content>

      </RepeatButton>

      • RepeatButton控件类似于Button控件,不同在于它可以控制触发的Click事件的时间和触发的方式,从按下RepeatButton按钮开始它就会按照一定的时间间隔重复的引发Click时间。
      • Delay:表示按下后开始重复引发click时间前等待的时间。
      • Interval:表示重复引发click事件的时间间隔。
      • 其他参数同Button控件
    • HyperLinkButton:

      <HyperlinkButton x:Name="MyHyperlinkButton" Height="16" Width="40" Content="百度" NavigateUri="http://www.baidu.com" TargetName="_blank" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">

      </HyperlinkButton>

      • HyperlinkButton 超链接按钮控件。
      • NavigateUri设置或获取单击HyperlinkButton控件时要导航到的uri
      • TargetName:要导航到得目标窗口或框架的名称,对应于标准HTML中的Targ
      • HorizontalContentAlignmentVerticalContentAlignment为设置水平、垂直对齐方式。

    二、文本编辑类控件(包括TextBox、PasswordBox)

    • TextBox:

      <TextBox x:Name="MyTextBox" Height="102" Margin="69,111,69,87" Width="262" Background="White" VerticalAlignment="Center" HorizontalAlignment="Center" IsReadOnly="False" IsEnabled="True" AcceptsReturn="True" SelectionBackground="Red" SelectionForeground="Black" SelectionChanged="MyTextBox_SelectionChanged">

      </TextBox>

      • Background:文本框控件的背景颜色。
      • IsReadOnly:是否为只读,如果为只读,不能更改文本框的内容
      • IsEnabled:控件是否可用。
      • AcceptsReturnTrue为多行文本框
      • SelectionBackground:选中的文本框内容的背景颜色
      • SelectionForeground 选中的文本框内容的文字颜色
      • SelectionChanged:选中文本框那位内容时候出发的事件。
      • SelectionLength:获取或设置选中的文本的长度。
      • SelectionStart:设置或获取文本框中选中文版的起始位置。
      • SelectionText:获取或设置当前文本框中选中的内容。
      • Text:读取或设置当前文本框的内容。

      private void MyRepeatButton_Click(object sender, RoutedEventArgs e)

      {

      MyTextBox.Text = "月落乌啼霜满天";

      MyTextBox.SelectionBackground = new SolidColorBrush(Colors.Red);

      MyTextBox.SelectionForeground=new SolidColorBrush(Colors.White);

      MyTextBox.SelectionStart = 1;

      MyTextBox.SelectionLength = 3;

      }

      private void MyTextBox_LostFocus(object sender, RoutedEventArgs e) //TextBox失去焦点时触发的事件

      {

      if (MyTextBox.Text == "")

      {

      MyTextBox.Text = "请输入用户名";

      MyTextBox.FontSize = 11;

      MyTextBox.FontStyle = FontStyles.Italic;

      MyTextBox.Foreground = new SolidColorBrush(Colors.Gray);

      }

      }

      private void MyTextBox_GotFocus(object sender, RoutedEventArgs e)//textbox获得焦点时候触发的事件

      {

      MyTextBox.Text = "";

      SolidColorBrush mycolor = new SolidColorBrush();

      mycolor.Color = Colors.Red;

      MyTextBox.Foreground = mycolor;

      }

    • PasswordBox:

      用于提供密码输入,可以在PasswordBox控件中输入一行不换行的内容,而用户无法查看输入的文本,只显示表示文本的密码字符。可以通过PasswordChar属性来制定此密码字符,通过password属性来获得用户输入的密码。

  • 相关阅读:
    团队冲刺第四天
    团队冲刺第三天
    找1的个数
    寻找最水之王
    最优价格买书
    团队冲刺第二天
    团队冲刺第一天
    团队开发项目特点
    第一阶段冲刺站立会议报告——4
    第一阶段冲刺站立会议报告——3
  • 原文地址:https://www.cnblogs.com/wandd/p/2713093.html
Copyright © 2020-2023  润新知