Monday, May 24, 2010

Setting properties of Silverlight controls from Code-behind

TextBox tb = new Textbox();
tb.FontStyle = FontStyles.Italic;
tb.Foreground = new SolidColorBrush(Color.FromArgb(255, 51, 51, 51));
tb.Background = new SolidColorBrush(Colors.Red);
tb.SetValue(Grid.RowProperty, 0);
tb.SetValue(Grid.ColumnProperty, 0);
tb.SetValue(Grid.ColumnSpanProperty, 2);

Image img = new Image();
BitmapImage imgSource = new BitmapImage(new Uri("Images/thumb.png", UriKind.Relative));
img.Source = imgSource;

TextBlock tooltip = new TextBlock();
tooltip.Text = "Hello";
ToolTip tt = new ToolTip();
tt.Content = tooltip;
ToolTipService.SetToolTip(img, tt);

No comments:

Post a Comment