Archive

Archive for the ‘WPF’ Category

How to Text Wrap a Label in WPF?

January 26th, 2010 joy No comments

WPF does not allow text wrapping for label control.Thus to wrap a label with a fixed width,we have to place the TextBlock control inside the label control and set its TextWrapping property to “Wrap”.

<Label Width=”50″>
<TextBlock TextWrapping=”Wrap”> I am label with width 50</TextBlock>
</Label>

Popularity: 8% [?]

Categories: C#, WPF Tags:

How To Call a Button Click From Another Button in c#

November 8th, 2009 joy No comments

If there is a requirement for calling a button click event from another button in c#, there is a easy way to do.We just need to call the PerformClick Method of the button to be fired.

private void button1_Click(object sender, EventArgs e)
{
    button2.PerformClick();
}
 
private void button2_Click(object sender, EventArgs e)
{
    System.Windows.Forms.MessageBox.Show("I am called from button1");
}

Popularity: 5% [?]

Make Textbox Number Only – WPF

September 28th, 2009 joy No comments

Coding :

private void txt_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !ValidNumeric(e.Text);
base.OnPreviewTextInput(e);
}
 
bool ValidNumeric(string str)
{
bool ret = true;
 
int l = str.Length;
for (int i = 0; i &lt; l; i++)
{
char ch = str[i];
ret &= Char.IsDigit(ch);
}
 
return ret;
}

Thanks dedjo

Popularity: 6% [?]

Categories: C#, WPF Tags: ,