zoukankan      html  css  js  c++  java
  • 一个简单的数据绑定,用slider和TextBox控制字体大小

    前台代码XAML
    <Window x:Class="WpfApplication4.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300" WindowState="Normal" WindowStartupLocation="CenterScreen">
        <StackPanel Margin="5">
            <Slider Name="sliderFontSize" Margin="3" Minimum="1" Maximum="40" Value="10" TickFrequency="1"
                    IsSnapToTickEnabled="True" TickPlacement="TopLeft">
            </Slider>
            <TextBlock Margin="10" Name="lbSimpleText" Text="Simple text"
                       FontSize="{Binding ElementName=sliderFontSize,Path=Value,Mode=TwoWay}"></TextBlock>
            <StackPanel Orientation="Horizontal">
                <Button Margin="5" Padding="3" Click="cmd_SetSmall">Set to small</Button>
                <Button Margin="5" Padding="3" Click="cmd_SetNormal">Set to Noarmal</Button>
                <Button Margin="5" Padding="3" Click="cmd_SetBig">Set to Big</Button>
            </StackPanel>
            <StackPanel  Orientation="Horizontal" Margin="5" >
                <TextBlock VerticalAlignment="Center" xml:space="preserve">Exact size: </TextBlock>
                <TextBox Text="{Binding ElementName=lbSimpleText,Path=FontSize,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Width="100"></TextBox>
            </StackPanel>
                </StackPanel>
    </Window>

    后台代码 C#
    private void cmd_SetSmall(object sender, RoutedEventArgs e)
    {
        sliderFontSize.Value = 2;
    }
    private void cmd_SetNormal(object sender, RoutedEventArgs e)
    {
        sliderFontSize.Value = this.FontSize;
    }
    private void cmd_SetBig(object sender, RoutedEventArgs e)
    {
        sliderFontSize.Value = 30;
    }

    单片机,嵌入式LINUX技术交流群:142282597
  • 相关阅读:
    Python 中多线程之 _thread
    Python ftplib 模块关于 ftp的下载
    nessus 漏洞扫描安装和使用
    实战medusa暴力破解
    浅谈python 中正则的一些函数
    一句话木马和中国菜刀的结合拿webshell
    浅说套接字socket做个小小的监控
    小巧的ssh客户端
    统计字符串的数字,英文字母,空格及其他的个数
    mysql字符串函数
  • 原文地址:https://www.cnblogs.com/qiujiahong/p/3173302.html
Copyright © 2011-2022 走看看