Adding gradientbrush to Hello World application

  • Thread starter Thread starter Alex. O. Koranteng
  • Start date Start date
A

Alex. O. Koranteng

I am getting started with Sliverlight 2.0 and created my first HelloWorld app
following the steps outlined from the Hands-On-labs documentation. The
solution works but it required me to add gradientbrush per the following

Open other supported browsers for Silverlight and access the same URL and
check that the application still works.
12. You may also open the SL2Demo solution in Expression Blend 2 SP1 and add
a gradient brush to the canvas. To do this, from within Visual Studio you can
right-click on a XAML file and choose “Open in Expression Blend†which will
open the solution in Expression Blend. Try to add a header to the screen as
shown below when tested:

I performed the above steps but need help on how accomplish the above.

Below is my code for the Page.XAML.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication1
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}

private void buttonHello_Click(object sender, RoutedEventArgs e)
{
this.txtSayHello.Text = "Hello, " + this.txtName.Text;
}
}
}

Below is the code for my Page.XAMl

<UserControl x:Class="SilverlightApplication1.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="Bisque" >

<Canvas>
<TextBlock Text="Enter a Name" Canvas.Left="64" Canvas.Top="55"/>
<TextBox x:Name="txtName" Canvas.Left="180" Canvas.Top="55"
Height="25" Width="100"/>
<Button x:Name="buttonHello" Canvas.Left="120" Canvas.Top="105"
Width="100" Content="Say Hello" Click="buttonHello_Click"/>
<TextBlock x:Name="txtSayHello" Canvas.Left="100"
Canvas.Top="150"/>
</Canvas>
</Grid>




Any suggestions will be appreciated
 
Hi Alex,

The Expression Blend is a designer. All actions we do in the Blend can be
achieved by the directly modifying the Page.xaml file. To assign a gradient
brush to the canvas, we can use the following xaml file,

<UserControl x:Class="SL2Hello.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<Canvas>
<Canvas.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="White" Offset="0.0"></GradientStop>
<GradientStop Color="LimeGreen"
Offset="0.5"></GradientStop>
<GradientStop Color="Green" Offset="1.0"></GradientStop>
</LinearGradientBrush>
</Canvas.Background>
<TextBlock Text="Enter a Name" Canvas.Left="64"
Canvas.Top="55"/>
<TextBox x:Name="txtName" Canvas.Left="180" Canvas.Top="55"
Height="25" Width="100"/>
<Button x:Name="buttonHello" Canvas.Left="120" Canvas.Top="105"
Width="100"
Content="Say Hello" Click="buttonHello_Click"/>
<TextBlock x:Name="txtSayHello" Canvas.Left="100"
Canvas.Top="150"/>
</Canvas>
</Grid>
</UserControl>


Best regards,
Colbert Zhou
Microsoft Newsgroup Support Team
 
Back
Top