WPF outsourcing companies: differences between WPF and Silverlight

Source: Internet
Author: User
Differences between WPF and Silverlight

This article will discuss the key differences between WPF and Silverlight. I hope this article will help you better understand the two.
When Silverlight was born, many people simply understood it as a flash competitor. However, with the further work of Microsoft, Silverlight is more and more widely used, and even many people confuse it with WPF. This article will be detailed for you.

As WPF and Silverlight become more and more important to. NET developers, the boundaries between them become increasingly vague. In June, wintellect published a little-known but extremely important White Paper on similarities and differences between Microsoft WPF and Silverlight ". We recommend that Gui developers read through all 69 pages. We will list the main points of view and their impact on related business developers.

Dependency attributes are an important part of the two platforms. propertymetadata can be used to save attributes instead of common fields. Silverlight only provides this class, but WPF has several child types available.

Uipropertymetadata adds an identifier to determine whether to disable dependency attribute animation where metadata instances are used"

Frameworkpropertymetadata adds an identifier to indicate the attributes that affect the MPs queue, including control management, measurement, and rendering. It can also be used to indicate whether the attribute allows data binding and the default type. Because Silverlight does not support this class, all data binding is unidirectional by default.

Silverlight does not support tunnel events. Both platforms support direct events and bubbling events.

WPF supports multiple types of triggers. After a simple trigger is attached to the Dependency Property, the style is automatically modified when the trigger condition is met. Besides simple triggers, WPF also supports responding to routing events or using data binding triggers.

Silverlight uses the visual status manager instead of the trigger. WPF does not currently provide this technology, but will add it in WPF 4.0.

Silverlight only supports several tag extensions. Besides common staticresource, binding, and templatebinding extensions, WPF also adds dynamicresource, relativesource, X: type, X: static, and X: array.

Many keyboard and mouse events are only available in WPF. Due to the large number of relationships, we will list the complete list later.

For the uielement class and the iinputelement interface. When a control is disabled, WPF uses them to disable all child controls. Silverlight does not provide this function, so developers have to manually traverse the control tree.

In terms of communication, Silverlight is limited to basichttpbinding and pollingduplexhttpbinding. Of course, WPF supports all bindings.

Finally, the print function is completely different between the two. WPF can directly print the visual tree, while Silverlight depends on the browser.

 

Windows Presentation Foundation (Windows appearance basics) is a new generation of Windows interface development technology based on framework 3.0 (including later versions.

Silverlight is a Web application product of WPF. Its name was WPF/e. It is mainly used in Web rich client applications (RIA, rich
Interface Application ). At this stage, this technology can be said to be quite popular. Microsoft's main rival in this aspect is Adobe's flash-based flex technology.

Both of them are based on XAML and can be converted to each other under certain conditions: for example, defining a simple argb color edition application:

The WPF application is as follows:

  • XAML file:
<Window x:Class="WPFColorVersion.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF Color Version" Height="300" Width="400" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
<Canvas Margin="0,0,0,0">
<Canvas.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF6254E2" Offset="0.996"/>
<GradientStop Color="#FFFFFFFF" Offset="0"/>
</LinearGradientBrush>
</Canvas.Background>
<TextBlock Height="34" Canvas.Left="28" Canvas.Top="17" Text="WPF Color Version" TextWrapping="Wrap" FontSize="24"
FontFamily="Comic Sans MS" FontWeight="Bold"/>
<TextBlock Height="34" Canvas.Left="22" Canvas.Top="38" FontFamily="Comic Sans MS" FontSize="24" FontWeight="Bold"
Text="WPF Color Version" TextWrapping="Wrap" RenderTransformOrigin="0.5,0.5">
<TextBlock.Foreground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF000000" Offset="1"/>
<GradientStop Color="#FFD9DFF0" Offset="0.026"/>
<GradientStop Color="#FF7D818B" Offset="0.78"/>
</LinearGradientBrush>
</TextBlock.Foreground>
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="-1"/>
<SkewTransform AngleX="-29" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
<Rectangle Fill="#00000000" Width="156" Height="103" Canvas.Left="219" Canvas.Top="108" x:Name="demoArea" />
<TextBlock Width="15" Height="17" Canvas.Top="116" Text="A" TextWrapping="Wrap" Canvas.Left="28" HorizontalAlignment="Center"/>
<TextBlock Width="15" Height="17" Canvas.Left="28" Canvas.Top="142" Text="R" TextWrapping="Wrap" HorizontalAlignment="Center"/>
<TextBlock Width="15" Height="17" Canvas.Left="28" Canvas.Top="166" Text="G" TextWrapping="Wrap" HorizontalAlignment="Center"/>
<TextBlock Width="15" Height="17" Canvas.Left="28" Canvas.Top="194" Text="B" TextWrapping="Wrap" HorizontalAlignment="Center"/>
<Slider Width="148" Height="22" Canvas.Left="43" Canvas.Top="111" Maximum="255" x:Name="sliderA" ValueChanged="sliderValueChanged"/>
<Slider Width="148" Height="22" Canvas.Left="43" Canvas.Top="137" Maximum="255" x:Name="sliderR" ValueChanged="sliderValueChanged"/>
<Slider Width="148" Height="22" Canvas.Left="43" Canvas.Top="163" Maximum="255" x:Name="sliderG" ValueChanged="sliderValueChanged"/>
<Slider Width="148" Height="22" Canvas.Left="43" Canvas.Top="189" Maximum="255" x:Name="sliderB" ValueChanged="sliderValueChanged"/>
<TextBlock Width="75" Height="17" Canvas.Left="143" Canvas.Top="230" Text="Color Value:"/>
<TextBox Width="89" Height="20" Canvas.Left="219" Canvas.Top="227" Text="#00000000" x:Name="txtColorValue"/>
</Canvas>
</Window>
  • Code file:
using System.Windows;
using System.Windows.Media;

namespace WPFColorVersion
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void sliderValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
{
byte a = (byte)(sliderA.Value);
byte r = (byte)(sliderR.Value);
byte g = (byte)(sliderG.Value);
byte b = (byte)(sliderB.Value);

Color clr = Color.FromArgb(a, r, g, b);

demoArea.Fill = new SolidColorBrush(clr);
txtColorValue.Text = clr.ToString();
}
}
}

In Silverlight, in The XAML file:

<Usercontrol X: class = "silverlightcolorversion. mainpage"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Width = "400" Height = "300">
<! -- This location is exactly the same as the XAML file content of the WPF project -->
</Usercontrol>
 

In addition, the content of the Silverlight code file is the same as that in the WPF project.

It can be seen that WPF is closely related to Silverlight and we can compare each other in the learning process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.