Monday, March 9, 2009

WPF Multiline Textbox

To make a textbox multiline unlike windows forms .Multiline = “True”, in WPF you have to set these 3 properties of TextBox Control.

  1. TextWrapping="Wrap"
  2. VerticalScrollBarVisibility="Visible"
  3. AcceptsReturn="True"

e.g.

<TextBox Height="66" Margin="563,46,265,0" Name="textBox1" VerticalAlignment="Top" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible"/>

Sunday, March 8, 2009

Get Checkbox state in WPF

In normal WinForms application you use Checkbox.Checked property to get or set value from your checkbox control, but when you try same thing in a WPF application you will get an error when you do the following.

   1: this.chkIsDayOff.Checked = _selectedOccasionType.BlnIsDayOff;




and the error will be …

“The event 'System.Windows.Controls.Primitives.ToggleButton.Checked' can only appear on the left hand side of += or –=”

Because Checked which was property in WinForms, is now Event in WPF.


To resolve this issue use IsChecked Property, both for setting to checkbox or getting from checkbox.




   1: this.chkIsDayOff.IsChecked = _SelectedOccasionType.BlnIsDayOff;