![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Simple Question re: Text in UserControl? All: I have created a simple custom control (UserControl derivative). When the control is displayed, I would like it to display some text. What do I add to the XAML below (C# code is fine as well) to have the control display some static text? This seems like it should be a no-brainer, but... <UserControl x:Class="JeopardyControl.GamePanel" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > <Rectangle x:Name="JeopardySquare" Canvas.Top="0" Canvas.Left="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="5" RadiusX="10" RadiusY="10" TextElement.Foreground="White"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> <LinearGradientBrush.GradientStops> <GradientStop Color="#0000ff" Offset="0" /> <GradientStop Color="#000088" Offset="1" /> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> </UserControl> Thanks, jpuopolo PS. When I tried this.AddText("xxx"), I got the following exception: Content of a ContentControl must be a single element |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Simple Question re: Text in UserControl? Hi, john wrote: > All: > > I have created a simple custom control (UserControl derivative). When > the control is displayed, I would like it to display some text. What do > I add to the XAML below (C# code is fine as well) to have the control > display some static text? This seems like it should be a no-brainer, > but... > > <UserControl x:Class="JeopardyControl.GamePanel" > xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > > <Rectangle x:Name="JeopardySquare" > Canvas.Top="0" Canvas.Left="0" VerticalAlignment="Stretch" > HorizontalAlignment="Stretch" > Margin="5" RadiusX="10" RadiusY="10" TextElement.Foreground="White"> > <Rectangle.Fill> > <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> > <LinearGradientBrush.GradientStops> > <GradientStop Color="#0000ff" Offset="0" /> > <GradientStop Color="#000088" Offset="1" /> > </LinearGradientBrush.GradientStops> > </LinearGradientBrush> > </Rectangle.Fill> > </Rectangle> > </UserControl> > > Thanks, > jpuopolo > > PS. When I tried this.AddText("xxx"), I got the following exception: > Content of a ContentControl must be a single element But this single element can be a panel, which in turn can contain multiple elements. Choose a panel (StackPanel, WrapPanel, Canvas, Grid, etc...) and make it your control's only child. The type you choose depends on the features you want, each panel has different placements options. The simplest is StackPanel, where each element is simply added after the other vertically or horizontally. Grids are perfect for build columns/rows oriented layouts. In Canvas, you can place your elements with X/Y measurements. WrapPanels are like StackPanels, but the elements get wrapped when the panel is resized. etc... Then, place your elements inside the panel. For simple text, you may want to use a Label or a TextBlock control. Check the documentation to see what they can do. HTH, Laurent -- Laurent Bugnion, GalaSoft Software engineering: http://www.galasoft-LB.ch Private/Malaysia: http://mypage.bluewin.ch/lbugnion Support children in Calcutta: http://www.calcutta-espoir.ch |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re:simple text encrypt / decrypt | VB Script | |||