In last article Currency Conversion WCF Service For Silverlight, I discussed how you will go about writing a WCF application that will consume WCF service. Following image shows how the UI for the application looks like.

(转) Write Silverlight Application To Consume Currency Converter WCF Service

As you can see, a very simple layout. There are 2 dropdown combo boxes that contain list of currencies available. And a button that you can click to submit selected currencies to get conversion rate.

Adding Reference To WCF Service

Since the whole application depends on communication with WCF service that serves currency conversion rates, first thing that needs to be done is to add reference to the service so the proxy classes can be created. The application uses these proxy classes to connect to WCF service. You can right click on References or Service Reference node in solution explorer and then follow the wizard steps to add reference to WCF service that we created. Following images show the process of adding service reference.

(转) Write Silverlight Application To Consume Currency Converter WCF Service

(转) Write Silverlight Application To Consume Currency Converter WCF Service

Populating Silverlight ComboBox

There are two input data points for this Silverlight control or applications. A source (from) and target (to) currency for which you want to get conversion rate. The application itself does not contain that list. This list comes from WCF service that I implemented. In this day and age where bigger countries get broken into smaller ones, it made more sense to serve this list from service instead of having a hard coded list in the application itself. Lets look at XAML mark up for ComboBox.

<ComboBox Grid.Column="1" Grid.Row="1" x:Name="cbFromCurrency" 
   ItemsSource
="{Binding}" Width="250" 
   IsEnabled
="False" Margin="0 0 0 10">
    
<ComboBox.ItemTemplate>
        
<DataTemplate>
        
<StackPanel Orientation="Horizontal">
            
<TextBlock Text="{Binding Country}"></TextBlock>
            
<TextBlock Text=","></TextBlock>
            
<TextBlock Text="{Binding Name}"></TextBlock>
            
<TextBlock Text="("></TextBlock>
            
<TextBlock Text="{Binding Symbol}"></TextBlock>
            
<TextBlock Text=")"></TextBlock>
        
</StackPanel>
        
</DataTemplate>
        
</ComboBox.ItemTemplate>
</ComboBox>

相关文章:

  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2021-12-09
  • 2022-12-23
  • 2021-11-08
  • 2021-11-06
猜你喜欢
  • 2021-08-23
  • 2021-07-05
  • 2021-07-10
  • 2021-11-28
  • 2021-12-01
  • 2021-09-25
  • 2021-11-16
相关资源
相似解决方案