62,025
社区成员
发帖
与我相关
我的任务
分享
<navigation:Page x:Class="SilverlightTest.Real"
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"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="Real Page">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="选择控件" Margin="5,10,10,10" FontSize="18" FontWeight="Bold" Foreground="#FFBE4D4D" Grid.Row="0"></TextBlock>
<Grid Grid.Row="1" Margin="5,0,0,5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="字体:" Grid.Row="0" Grid.Column="0"></TextBlock>
<ComboBox Name="fontComboBox" Width="150" ItemsSource="{Binding}" Grid.Row="0" Grid.Column="1" SelectionChanged="fontComboBox_SelectionChanged"></ComboBox>
<TextBlock Text="大小:" Grid.Row="0" Grid.Column="2"></TextBlock>
<ComboBox Name="fontSizeComboBox" Width="80" Grid.Row="0" Grid.Column="3" SelectionChanged="fontSizeComboBox_SelectionChanged">
<ComboBoxItem Content="12" IsSelected="True"></ComboBoxItem>
<ComboBoxItem Content="13"></ComboBoxItem>
<ComboBoxItem Content="14"></ComboBoxItem>
<ComboBoxItem Content="15"></ComboBoxItem>
<ComboBoxItem Content="16"></ComboBoxItem>
</ComboBox>
<TextBlock Name="textBlock1" Text="测试内容" Margin="10,5,0,0" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4">
</TextBlock>
<TextBlock Name="textBlock2" Text="测试内容2" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" Margin="10,5,0,0"></TextBlock>
<TextBlock Name="textBlock3" Text="测试内容3" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" Margin="10,5,0,0"></TextBlock>
<TextBlock Name="textBlock4" Text="测试内容4" Margin="10,5,0,0" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="4">
</TextBlock>
<TextBlock Name="textBlock5" Text="测试内容5" Margin="10,5,0,0" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="4">
</TextBlock>
</Grid>
</Grid>
</navigation:Page>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.Collections.ObjectModel;//ObservableCollection
namespace SilverlightTest
{
public partial class Real : Page
{
public Real()
{
InitializeComponent();
ObservableCollection<FontFamily> fonts = new ObservableCollection<FontFamily>();
fonts.Add(new FontFamily("Cambria"));
fonts.Add(new FontFamily("Arial Unicode MS"));
fonts.Add(new FontFamily("Batang"));
fonts.Add(new FontFamily("Dotum"));
this.fontComboBox.DataContext = fonts;//这样完成了绑定;
this.fontComboBox.SelectedItem = new FontFamily("Cambria");//默认值
}
// 当用户导航到此页面时执行。
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void fontComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox cb = sender as ComboBox;
this.textBlock1.FontFamily = (FontFamily)cb.SelectedItem;
this.textBlock2.FontFamily = (FontFamily)cb.SelectedItem;
this.textBlock3.FontFamily = (FontFamily)cb.SelectedItem;
this.textBlock4.FontFamily = (FontFamily)cb.SelectedItem;
this.textBlock5.FontFamily = (FontFamily)cb.SelectedItem;
}
private void fontSizeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox cb = sender as ComboBox;
int fontSize = int.Parse(((ComboBoxItem)cb.SelectedItem).Content.ToString());
this.textBlock1.FontSize = double.Parse(fontSize.ToString());
this.textBlock2.FontSize = fontSize+1;
this.textBlock3.FontSize = fontSize+2;
this.textBlock4.FontSize = fontSize+3;
this.textBlock5.FontSize = fontSize + 4;
}
}
}
private void fontSizeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox cb = sender as ComboBox;
int fontSize = int.Parse(((ComboBoxItem)cb.SelectedItem).Content.ToString());
if(cb.SelectedItem!=null)
{
//再设置字体?
}
}