Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Simple Question re: Text in UserControl?

 
 
Old 11-29-2006   #1 (permalink)
john


 
 

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 SpecsSystem Spec
Old 11-30-2006   #2 (permalink)
Laurent Bugnion


 
 

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 SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Re:simple text encrypt / decrypt VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46