一个简单的数据绑定,用slider和TextBox控制字体大小
2013-07-05 10:57
429 查看
前台代码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;
}
<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;
}
相关文章推荐
- winform有一个combobox和一个textbox控件,如何进行动态绑定,使得combobox中的数据改变时,textbox中的数据也随之改变?
- slider控件控制文本框字体大小
- JavaScript数据绑定实现一个简单的 MVVM 库
- C# WPF TextBox绑定数据的简单应用
- iOS一种简单的改变一个label上范围内字体颜色和大小的方法
- 一个简单的自适应调整字体大小view
- 利用 JavaScript 数据绑定实现一个简单的 MVVM 库
- 一个对大小固定的内存数据进行操作的简单类
- JavaScript数据绑定实现一个简单的 MVVM 库
- 自定义控件(14)编写一个简单的数据绑定控件
- ADO.NET Entity Framework 一个简单数据绑定例子
- ADO.NET Entity Framework 一个简单数据绑定例子
- Android UI设计之<十二>自定义View,实现绚丽的字体大小控制控件FontSliderBar
- ADO.NET Entity Framework 一个简单数据绑定例子
- 数据绑定(一)一个简单的例子
- 关于如何控制一个页面的Ajax读数据只读一次的简单解决办法!
- J简单的S实现控制背景颜色、修改字体大小
- 一个简单的win8数据绑定
- 一个简单的数据类型判断:占用不同大小字节的变量比较
- WP7之Slider绑定textblock设置字体大小