silverlight 生成二维码

时间:2023-03-08 17:20:15
silverlight 生成二维码

MainPage.xaml

  <Grid x:Name="LayoutRoot" Background="White">
<Border BorderThickness="" BorderBrush="Black" />
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height=""/>
<RowDefinition Height=""/>
<RowDefinition Height=""/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=""/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="二维码" Grid.Column="" Grid.Row="" TextAlignment="Center" Margin="10,50" />
<Image x:Name="imgCode" Grid.Column="" Grid.Row="" Margin=""/>
<TextBlock Text="图片大小" Grid.Column="" Grid.Row="" Margin="" TextAlignment="Center" />
<ComboBox x:Name="cmbSize" Grid.Column="" Grid.Row="" Width="" Height="" HorizontalAlignment="Right" Margin="0,10,100,10">
<ComboBoxItem Content="" IsSelected="True" />
<ComboBoxItem Content="" />
</ComboBox>
<TextBlock Text="二维码内容" Grid.Column="" Grid.Row="" TextAlignment="Center" Margin=""/>
<TextBox x:Name="txtContent" Height="" Margin="" Grid.Column="" Grid.Row="" />
<Button x:Name="btnAdd" Content="生成" Width="" Grid.Row="" Grid.Column="" Click="btnAdd_Click" Margin=""/>
</Grid>
</Grid>

MainPage.xaml.cs

  public partial class MainPage : UserControl
{
StringBuilder sb = null;
Uri uri = null;
public MainPage()
{
InitializeComponent();
sb = new StringBuilder();
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
sb.Append("http://chart.apis.google.com/chart?cht=qr&chs=");
sb.Append(((ComboBoxItem)cmbSize.SelectedItem).Content.ToString());
sb.Append("x");
sb.Append(((ComboBoxItem)cmbSize.SelectedItem).Content.ToString());
sb.Append("&chl=");
sb.Append(txtContent.Text);
uri = new Uri(sb.ToString());
imgCode.Source = new BitmapImage(uri);
sb.Clear();
}
}