|
|||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionIn this article, the author describes how to combine the AjaxControlToolkit (Ajax, ASP.NET), Silverlight ( For more interesting Silverlight articles, visit Codegod's Silverlight section. The ConceptWith Silverlight, one can create enhanced and rich user interfaces which can be displayed in a browser. These user interfaces are defined with the description-language XAML. With ASP.NET Futures, you can use the PrerequisitesBefore we can start, we have to install the needed software.
Create the WebsiteAfter installing the prerequisites, we can start with a new AjaxControlToolkit Website. Choose File->New Website->AjaxControlToolkit Website. Now your Website contains references to the AjaxControlToolkit.dll and the Microsoft.Web.Preview.dll. The first one is needed for the Toolkit's controls, the last one for the ASP.NET Futures controls ( The ExampleIn our example Website, we want to display an image with a border on a SilverLight-Canvas. Beyond that, we want to give the user the possibility to rotate the displayed image with a Slider-control. There should not be a postback when the user changes the slider-position so the image has to be rotated by clientside script. Alright, let's add an XAML page with a <Canvas
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="640" Height="480"
x:Name="rootCanvas"
>
<Canvas.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFAAAAAA" Offset="0"/>
<GradientStop Color="#FFE2EAFF" Offset="0.5"/>
<GradientStop Color="#FF666666" Offset="1"/>
</LinearGradientBrush>
</Canvas.Background>
<Canvas Width="200" Height="200" x:Name="Cover" Canvas.Left="280" Canvas.Top="250">
<Canvas.RenderTransform>
<TransformGroup>
<RotateTransform x:Name = "rotObj" CenterX="0.5" CenterY="0.5" Angle="0"/>
</TransformGroup>
</Canvas.RenderTransform>
<Image Source="img/codegod.jpg" Stretch="Fill" Width="215" Height="120"/>
<Path Stroke="White" Data="M0,0L215,0 215,120 0,120z" StrokeThickness="15"/>
</Canvas>
</Canvas>
So we have a Canvas which has a size of 640x480 pixels. It has a linear gradient as background and a Canvas with a size of 200x200 pixels defined in the middle holding an image. This Canvas can be rotated by the Tag The Website's LayoutHere is the layout of the controls:
The <ajaxtoolkit:sliderextender ID="SliderExtender1" runat="server"
BehaviorID="Slider1"
TargetControlID="Slider1"
Minimum="0"
Maximum="360"
Steps="360" RaiseChangeOnlyOnMouseUp="False" />
Rotate: <asp:TextBox ID="Slider1" runat="server" AutoPostBack="True"
style="right:0px" Text="0"/>
As you can see, it has a Interaction with JavaScriptWe want the slider to change the rotation-angle of the inner Canvas. This means that we have to react on the change-event of the slider's value (the protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(Slider1);
Slider1.Attributes.Add("OnChange",
"sliderChanged('" + Slider1.ClientID + "');");
}
Now the function <script type="text/javascript" language="javascript">
var _rotObj;
function SL_Loaded(sender, args)
{
// Get the RotateTransform-object of the Xaml-Canvas
_rotObj = document.getElementById("Xaml1").content.findName('rotObj');
}
function sliderChanged( id )
{
// set the new rotation angle on slider-change
var slider = document.getElementById(id);
var rotAngle = slider.value;
_rotObj.Angle = rotAngle;
}
</script>
Not much code, isn't it? And the result looks really nice. Have fun with it, the project is attached. History
|
||||||||||||||||||||||||||||||||||||||||