Friday, April 20, 2007

Refering inner element through XAML

<StackPanel >
<TextBlock Text="{Binding ElementName=btn,Path=Foreground.Color.R}">
<Button Foreground="Red" Name="btn"/>


Get the template of 3rd party controls

If we dont have template of a Control we could get that using Blend.
Load the control in Blend and right click on it then select

Edit Control Parts(Template) -> Edit a Copy

This will create a copy of the template in xaml file.

Vista theme support in XP using WPF

This wont change the look and feel of the Window as in Vista ie the transparent window title.But changes the look and feel of the elements (Button,Combo etc) inside that Window.

Know the state of a object in XAML format at runtime

The below code gives the XAML representation of object at runtime.


Using this we can save the current state of the objects..

Creating a control from xaml string at runtime

string s = "< Button xmlns='' xmlns:x='' >";
s += "Hai";
s += " < /Button > ";

Stream strm = new MemoryStream(ASCIIEncoding.Default.GetBytes(s));
Button b = (Button)System.Windows.Markup.XamlReader.Load(strm);

How can we make a TextBox looks like Button using template?

If we wanna make the Button looks like TextBox it is easy,just add the TextBox as content of Button.But the reverse is not possible sice TextBox doesnt have Content property.So use Templating.

< TextBox Text="Hai" >
< TextBox.Template >
< ControlTemplate >
< Button Content="hai"/ >
< /ControlTemplate >
< /TextBox.Template >
< /TextBox >

CS Code

ControlTemplate ct=new ControlTemplate(typeof(TextBox));
FrameworkElementFactory fef=new FrameworkElementFactory(typeof(Button));
ct.VisualTree =fef;
txt.Template = ct;

Thursday, April 19, 2007

Access yahoo through XAML in WPF

See this and know how to access the information on yahoo through XPath

Start WPF 3D here

This helps us to understand what is Mesh,Normals etc and finally make us capable of creating a cube

Some WPF tutorial sites

WPF tutorials

Cheat sheets
WPF XAML Data Binding Cheat Sheet (PDF), latest version, updated February 2
 XAML for WPF Cheat Sheet 1.0

Some XAML & XBAP tutorials



WPF 2D controls in 3D viewport

Get the library from below link which helps us to include 2d controls like Button,Textbox etc into 3D viewport.

Also this will raise all the events such as Click,MouseDown of 2D controls.

New confusing things in WPF

DependencyObject and DependencyProperty
Logical and VisualTree
Tunnel and Bubble events
XBAP and Standalone applications
ControlTemplate and DataTemplate
Style and Template
Need to complete

Command and Event
Window and Page

Static and Dynamic resources

Tricks and tips in WPF / How to achieve things using WPF

Applying same style to all wpf elements of same type

The folloging code will give a Red background to all the Buttons in the Window provided if we didnt set the ButtonBackground explicitly

< Window.Resources >
< Style x:key="{x:Type Button}" TargeType="{x:Type Button}" >
< Setter Property ="Background" Value ="Red"/ >
< /Style >
< /Window.Resources >

C# Code

Style sty = new Style(typeof(Button));

Setter set = new Setter(Button.BackgroundProperty , Brushes.Red);


Resources.Add(typeof( Button), sty);


Sharing My WPF experiences....
The posts will contain links more which are useful than my own articles :-)