/Home /Archive /Syndicate /Blog /Support /About /Contact  
All Visual Basic Feeds in one place!





  One of the things that often pulls me up in mid flow when I'm putting WPF UIs together in a Window is that some of the core properties seem to have disappeared. Now, some of these are so fundamental that I know they have to be there, but obviously hiding under a different name.

  Just recently, this happened to me twice in a row and I ended up scrolling through the Properties in the Object Browser, getting dizzy with the whizzing list of choices until I finally found them. All I was looking for was a very simple thing in both cases. I just wanted to apply some text to a control.

  The first one was the good old CheckBox. In Windows Forms this has a Text property, of course, and it's whatever textual information you want to place at the side of the little square check area. The WPF CheckBox will allow you to do a zillion clever things to change its look - add Borders, TextBlocks, Images, Panels, whatever you like - and at times I'm really happy about that. But as it happened this time I just wanted to plonk a couple of words of description at the side.

  You'll have gathered that there isn't a Text property for the WPF CheckBox and after a bit of a search, I did find its replacement - the Content property. If you assign plain text to this property, WPF will honor your choice. So this:

   17 <CheckBox x:Name="CheckBox1" Content="Click Here" />

 

  will do the job nicely.

  Subsequently I discovered that the Content property is in fact the default property of a CheckBox, so this too will work:

   17  <CheckBox x:Name="CheckBox1">"Click Here"</CheckBox>

 

  Of course if you do want something more exotic, then you still use the Content property - you just add whatever multiple layers of content you desire.

   The other control for which I had to search for the same kind of thing was the Expander. Again I only wanted a property that would just tack some plain text to the side of the Expander's little arrow.

  This time the answer is to use the Expander's Header property.

<Expander Header="See More Choices"></Expander>

 

You can assign plain text to this property, but again you have the option to, well, expand the Expander's Header to make it a little more graphically interesting.

 

     

  using this XAML:

      <Expander.Header>

          <Border BorderBrush="Navy" BorderThickness="2" CornerRadius="6">

            <TextBlock Margin="10,2,10,2"

            Foreground="Navy">What do you want to do?</TextBlock>

          </Border>

        </Expander.Header>

 

  Although Content is the default property, don't fall into the trap of trying to use it as:

   20  <Expander> Click to view choices </Expander>

  because that inserts the text as the first (and in this case, only) item in the area that you get to see when the Expander arrow is clicked. It will be the only item because Content isn't a container and you need to use something like a StackPanel if you have more than one child that you want to include in the expanded area.

  Something like this:

      <Expander.Content>

          <StackPanel >

            <CheckBox Margin="2,4" Content=" Do This"></CheckBox>

            <CheckBox Margin="2,4" Content=" Do That"></CheckBox>

            <CheckBox Margin="2,4" >

              <CheckBox.Content>

                <StackPanel Orientation="Horizontal">

                  <Image Width="16" Source="DCP_1997.jpg"></Image>

                  <TextBlock Text=" View Profile"></TextBlock>

                </StackPanel>

              </CheckBox.Content>

            </CheckBox>

            <TextBlock TextWrapping="Wrap" Margin="3,30,0,0"

          Text="Select a task from the list above." />

          </StackPanel>

        </Expander.Content>

 

  to produce this result:

 

  

© 2005 Serge Baranovsky. All rights reserved.
All feed content is property of original publisher. Designated trademarks and brands are the property of their respective owners.

This site is maintained by SubMain(), a division of vbCity.com, LLC