首页 > 代码库 > silverlight 生成二维码

silverlight 生成二维码

MainPage.xaml

 1  <Grid x:Name="LayoutRoot" Background="White"> 2         <Border BorderThickness="2" BorderBrush="Black" /> 3         <Grid ShowGridLines="True"> 4             <Grid.RowDefinitions> 5                 <RowDefinition/> 6                 <RowDefinition Height="50"/> 7                 <RowDefinition Height="50"/> 8                 <RowDefinition Height="50"/> 9             </Grid.RowDefinitions>10             <Grid.ColumnDefinitions>11                 <ColumnDefinition Width="100"/>12                 <ColumnDefinition/>13             </Grid.ColumnDefinitions>14             <TextBlock Text="二维码" Grid.Column="0" Grid.Row="0" TextAlignment="Center" Margin="10,50" />15             <Image x:Name="imgCode" Grid.Column="1" Grid.Row="0" Margin="2"/>16             <TextBlock Text="图片大小" Grid.Column="0" Grid.Row="1" Margin="10" TextAlignment="Center" />17             <ComboBox x:Name="cmbSize" Grid.Column="1" Grid.Row="1" Width="100" Height="30" HorizontalAlignment="Right" Margin="0,10,100,10">18                 <ComboBoxItem Content="100" IsSelected="True" />19                 <ComboBoxItem Content="150" />20             </ComboBox>21             <TextBlock Text="二维码内容" Grid.Column="0" Grid.Row="2" TextAlignment="Center" Margin="10"/>22             <TextBox x:Name="txtContent" Height="30" Margin="5" Grid.Column="1" Grid.Row="2" />23             <Button x:Name="btnAdd" Content="生成" Width="100"  Grid.Row="3" Grid.Column="1" Click="btnAdd_Click" Margin="5"/>24         </Grid>25     </Grid>
View Code

MainPage.xaml.cs

 1  public partial class MainPage : UserControl 2     { 3         StringBuilder sb = null; 4         Uri uri = null; 5         public MainPage() 6         { 7             InitializeComponent(); 8             sb = new StringBuilder(); 9         }10         private void btnAdd_Click(object sender, RoutedEventArgs e)11         {12             sb.Append("http://chart.apis.google.com/chart?cht=qr&chs=");13             sb.Append(((ComboBoxItem)cmbSize.SelectedItem).Content.ToString());14             sb.Append("x");15             sb.Append(((ComboBoxItem)cmbSize.SelectedItem).Content.ToString());16             sb.Append("&chl=");17             sb.Append(txtContent.Text);18             uri = new Uri(sb.ToString());19             imgCode.Source = new BitmapImage(uri);20             sb.Clear();21         }22     }
View Code