The following is the small example for displaying current datetime in XAML.
In XAML you need to first add the mscorlib assembly and the System namespace, then you can use use the {x:Static sys:DateTime.Now} in your code like this: Continue reading “Show Date time in xaml”
Tag: WPF
writing text in rectangle in xaml
The following code snippet of XML create a rectangle and put some text inside into rectangle by using Border control. Continue reading “writing text in rectangle in xaml”
Animation in thickness of a Border in wpf
The following example shows how to apply animation in the thickness of a Border control by using ThicknessAnimation class:
Continue reading “Animation in thickness of a Border in wpf”
Write text inside shapes using Border control in wpf
We know that WPF Shapes (such as ellipse,rectangle etc) are not container control, so we can put some text directly inside them or we will have to work extra for doing that but we can do this with the help of Border control very easily. Continue reading “Write text inside shapes using Border control in wpf”
How to fill a shape with an image in WPF
If you want to fill a shape with an image, suppose you have an ellipse on your form and you want to fill this ellipse with an image then you can use ImageBrush class that enable us to paint an area with an image. An ImageBrush paints an area with an ImageSource property. Continue reading “How to fill a shape with an image in WPF”
How to insert MaskedTextBox control on a WPF page at runtime
Some time you need to use windows form control on your WPF page so i shows you how to host a MaskedTextBox windows form control on a WPF page at runtime with the help of the following example:
Continue reading “How to insert MaskedTextBox control on a WPF page at runtime”
How to sort data in Listbox in WPF
This example describes how to sort data in a view.
In this example we create a simple ListBox control named lstBox and a two Buttons: Continue reading “How to sort data in Listbox in WPF”
How to rotate shape in XAML
The Transform class provides the means to transform shapes in a two-dimensional plane.
Continue reading “How to rotate shape in XAML”
Line shape in WPF
WPF provides a number of ready-to-use Shape objects. All shape objects inherit from the Shape class. Available shape objects include Ellipse, Line, Path, Polygon, Polyline, and Rectangle. Shape objects share the following common properties.
Stroke : Describes how the shape’s outline is painted.
StrokeThickness : Describes the thickness of the shape’s outline.
Fill : Describes how the interior of the shape is painted.
in this article we learn that how to draw various type of line shape.
The Line class enables you to draw a line between two points. The following example shows several ways to specify line coordinates and stroke properties.
Draws a diagonal line
<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="wpfEllipse" Width="300" Height="300"> <Canvas Height="200" Width="250"> <Line X1="50" Y1="50" X2="200" Y2="100" Stroke="Black" StrokeThickness="4" /> </Canvas> </Window>
above code produce this result:
Draws a diagonal line with gradient effect
<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Line in WPF" Width="292" Height="182"> <Canvas Height="150" Width="250"> <Line X1="10" Y1="10" X2="100" Y2="150" StrokeThickness="4" Canvas.Left="100"> <Line.Stroke> <RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5" RadiusX="0.5" RadiusY="0.5"> <RadialGradientBrush.GradientStops> <GradientStop Color="Red" Offset="0" /> <GradientStop Color="green" Offset="0.75" /> </RadialGradientBrush.GradientStops> </RadialGradientBrush> </Line.Stroke> </Line> </Canvas> </Window>
above code produce this result:
Draws a horizontal line
you can draw horizantal line in xaml with same Y1and Y2 points.
<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Line in WPF" Width="292" Height="182"> <Canvas Height="150" Width="250"> <Line X1="10" Y1="60" X2="240" Y2="60" Stroke="Black" StrokeThickness="4"/> </Canvas> </Window>
above code produce this result:
Draws a vertical line
you can draw vertical line in xaml with same X1 and X2 points.
<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Line in WPF" Width="292" Height="182"> <Canvas Height="146" Width="98"> <Line X1="50" Y1="10" X2="50" Y2="140" Stroke="Black" StrokeThickness="4"/> </Canvas> </Window>
above code produce this result:
ContextMenu in WPF
This article describe that how to use Contextmenu control in XAML and Code.A ContextMenu is attached to a specific control. The ContextMenu element enables you to present users with a list of items that specify commands or options that are associated with a particular control,
Continue reading “ContextMenu in WPF”