Hi guys, One of the best feature available in Expression Blend is allowing the binding of any property of one control to relative property of other control. In this article you will learn how to add a text file from the strorage device and resize it and also save it back to the storage device. Apart from this you can also learn how to resize the image manually.
Follow the steps below :
Step 1 : Open Expression Blend.
- Open new Project as WPF application
- Name it as "resizing"
Step 2 : The page opens up with the design view. In this artboard add two buttons.
- Name One button as resizetext and change the content to "Resize Text"
- Name other button as resizeimg and change the content to "Resize image"
Step 3 : You can change the background image or color of the artboard also can change the color, Font etc property of the button to give better look and feel of the page. Now select the "Resize Text".
- Go to property and click on the event property of the button
- Now in I'll redirect this start page to the text resizing page
- In front of the Click event type the name of the Click method. Here I have named it as "textopen"
- Press Enter and type the following lines of code
public
partial
class
Start_page : Window
{
public
Start_page()
{
this.InitializeComponent();
}
private
void
textopen(object
sender, System.Windows.RoutedEventArgs e)
{
MainWindow mw =
new
MainWindow();
// here MainWindow is the name of the page used for resizing the text. Go to
step 5 to know about this.
mw.Show();
this.Close();
}
}
Step 4 : Similarly select the "Resize image" button.
-
In the CLick event property type the name of the method
-
Now in I'll redirect this start page to the image resizing page
-
Here I have named as "imgopen" and type the following lines of code
private
void
imgopen(object
sender, System.Windows.RoutedEventArgs e)
{
image_resizing ir =
new
image_resizing();
// here image_resizing is
the name of the page used for resizing the image. Go to step 5 to know about
this.
ir.Show();
this.Close();
}
Step 5 : Now add a page for text resizing and name this page as MainWindow.
-
Go to File -->New Item-->Window
-
Name this page as MainWindow
Step 6 : This opens up a page with the artboard and design view. In this page add the following controls.
-
A Text box and expand it to approximate half the screen size and name it as "tb1"
-
A button named "addbtn" and change its content to "Add ". This button is to insert a text file in to the textbox for resizing
- Add andother button named "savebtn" and change its content to "Save ". This button is to save a text file
Step 7 : Now select the "Add" button.
- Go to property
- Click on the event button
- Type the name of the method in front of the click event. Here I have named it as add()
- Now write the following lines to add the text file into the textbox
using
System.Windows.Media.Imaging;
using
System.Windows.Shapes;
using
System.IO;
//Dont
forget to include this line
namespace
_d
{
public
partial
class
MainWindow : Window
{
public
MainWindow()
{
this.InitializeComponent();
}
private
void
add(object
sender, System.Windows.RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog fd =
new
Microsoft.Win32.OpenFileDialog();
fd.InitialDirectory =
"D:\\";
fd.Filter ="Text
files (*.txt)|*.txt";
fd.RestoreDirectory =
true
;
bool?
result = fd.ShowDialog();
if(result==true)
{
String mypath = fd.FileName.ToString();
if(File.Exists(mypath))
tb1.Text = System.IO.File.ReadAllText(mypath);
}
}
}
}
Step 8 : Now I'll add the line of code for the "Save" button to save the text file to the storage drive again.
- Select the "Save" button
- Go to property
- Type the name of the method in front of the Click event and press Enter
- Here I have named this method as save()
private
void
save(object
sender, System.Windows.RoutedEventArgs e)
{
Microsoft.Win32.SaveFileDialog svfd =
new
Microsoft.Win32.SaveFileDialog();
svfd.InitialDirectory =
"D:\\";
svfd.Filter ="Text
files (*.txt)|*.txt";
svfd.RestoreDirectory =
true
;
bool?
result = svfd.ShowDialog();
if(result==true) {
String mypath3 = svfd.FileName.ToString();
if(File.Exists(mypath3))
{
System.IO.File.Delete(mypath3);
}
using(
FileStream fs = File.Create(mypath3))
{
//here the
text content is read byte by byte and saved to the file
Byte[] txtcontent =
new
UTF8Encoding(true).GetBytes(tb1.Text);
fs.Write(txtcontent,0,txtcontent.Length);
}
}
}
Step 9 : Now the main task of resizing is to be accomplished. For this :
- Add a Slider control to the artboard
- Resize this slider control by using selection tool
- You may change the display color or gradient of this control
- Select this slider control
- Go to Property window--> Common property--> In the Maximum field type the value = 100;
Step 10 : Now select the Textbox and do the following changes to the properties.
- You can change the foreground/ background color/gradient
- In the artboard add a row separating the textbox and the slider control. For this run the mouse along the boundary of the artboard and mark a line border between thetextbox and the slider control
- Now go to property window --> layout property --> set the VerticalScrolbarVisibility property--> Auto
Step 11 : Next task is to bind the sliding value of the slider control and the text size. For this:
- Select the textbox
- Go to property --> Text property
- In this select the small square shaped advanced option button alongside of the font size property

- This opens a window--> In this select the Databinding option
- Again a window opens up--> select the Elementary data binding property--> Select Slider control--> In the list of binding properties select--> "value" property of the slider control. Press OK and exit

- Now the sliding value of the slider is bind with the font size of the Text in the Textbox
Step 12 : To see the effect just press F5 and check the application. You'll find that the application runs well showing the text font increasing with the slider movement. Also you can add and save the text file.
Step 13 :Now next job is to resize the image. Follow the steps below:
- Now add a page for resizing the image and name this page as image_resizing
-
Go to File -->New Item-->Window
-
Name this page as image_resizing
Step 14 : This opens up a page with the artboard and design view. In this page add the following controls
-
A image box and insert and image into this by dragging and dropping an image from the storage drive
-
Add 4 buttons named "hplus", "hminus", " wplus" and wminus" respectively for increasing and decreasing the height and width of the image
-
Now change the contents to "+ " and "-" respectively.See the fig to get it more clear:

- Add 2 text blocks and change their contents to "Height" and "Width" respectively
- Add 2 Textbox name them as "htext" and "wtext" respectively for the height and width value respectively. Change the content to any height or width value
- In the artboard add a row separating the imagebox and the height/width control. For this run the mouse along the boundary of the artboard and mark a line border between thetextbox and the slider control
Step 15 : Now select the "+" button in representing the height.
- Go to property
- Click on the event button
- Type the name of the method in front of the click event. Here I have named it as plus()
- Now write the following lines to increase the height of the image through button click
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Data;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Imaging;
using
System.Windows.Shapes;
namespace
_d
{
///
<summary>
///
Interaction logic for image_resizing.xaml
///
</summary>\
public
partial
class
image_resizing : Window
{
public
image_resizing()
{
this.InitializeComponent();
// Insert
code required on object creation below this point.
}
private
void
plus(object
sender, System.Windows.RoutedEventArgs e)
{
// TODO:
Add event handler implementation
img.Height = System.Convert.ToInt32(htext.Text) +
1;
htext.Text =System.Convert.ToString
(System.Convert.ToInt32(htext.Text) +
1);
}
Step 16 : Now select the "-" button in representing the height.
- Go to property
- Click on the event button
- Type the name of the method in front of the click event. Here I have named it as hmin()
- Now write the following lines to decrease the height of the image through button click
private
void
hmin(object
sender, System.Windows.RoutedEventArgs e)
{
img.Height = System.Convert.ToInt32(htext.Text) -
1;
htext.Text = System.Convert.ToString
(System.Convert.ToInt32(htext.Text) -
1);
}
Step 17 : Now select the "+" button in representing the width.
- Go to property
- Click on the event button
- Type the name of the method in front of the click event. Here I have named it as wp()
- Now write the following lines to increase the width of the image through button click
private
void
wm(object
sender, System.Windows.RoutedEventArgs e)
{
// TODO:
Add event handler implementation here.
img.Width = System.Convert.ToInt32(wtext.Text) -
1
;
wtext.Text = System.Convert.ToString
(System.Convert.ToInt32(wtext.Text) -
1);
}
Step 18 : Now select the "-" button in representing the width.
- Go to property
- Click on the event button
- Type the name of the method in front of the click event. Here I have named it as wm()
- Now write the following lines to decrease the width of the image through button click
private
void
wm(object
sender, System.Windows.RoutedEventArgs e)
{
// TODO:
Add event handler implementation here.
img.Width = System.Convert.ToInt32(wtext.Text) -
1
;
wtext.Text = System.Convert.ToString
(System.Convert.ToInt32(wtext.Text) -
1);
}
Step 19 : Now select the textbox in representing the height.
- Go to property
- Click on the event button
- Type the name of the method in front of the TextChanged event. Here I have named it as hg()
- Now write the following lines to change the height of the image through manually typing the height of the image
private
void
hg(object
sender, System.Windows.Controls.TextChangedEventArgs e)
{
// TODO:
Add event handler implementation here.
img.Height = System.Convert.ToInt32(htext.Text) ;
}
Step 20 : Now select the textbox in representing the height.
- Go to property
- Click on the event button
- Type the name of the method in front of the TextChanged event. Here I have named it as wd()
- Now write the following lines to change the width of the image through manually typing the width of the image
private
void
wd(object
sender, System.Windows.Controls.TextChangedEventArgs e)
{
// TODO:
Add event handler implementation here.
img.Width = System.Convert.ToInt32(wtext.Text) ;
}











Andrew FinlanderPosted Dec 26, 2011, 1:52 AM
Gud work manoj thaNKS FOR SHARING