views:

44

answers:

2

Hi,

I am dynamically creating the checkboxes at runtime and also applying the style at runtime. Designer has developed a checkbox like control that am applying at runtime. and he put a Label on that checkbox control to show the Text on the checkbox control as its content from the Database. But when i applying content of checkbox or label at runtime, it displays at the back of that checkbox control that is developed by the designer. How to make use of the Label control to show the content from the database on the checkbox control.

Kindly Suggest?

Thanks

A: 

You should to review your checkbox style. It is supposed to be that label(textbox) in style liyng under checkbox mark. Here is nearly right code for the chekcbox template:

<Grid>
   <Grid.ColumnDefinitions>
       <ColumnDefinition Width="Auto"/>
       <ColumnDefinition Width="*"/>
   </Grid.ColumnDefinitions>
   <Border Grid.Column="0">
      <!--Place your mark here-->
   </Border>
   <Border Grid.Column="1">
      <!--Place your label here-->
   </Border>
</Grid>
Eugene Cheverda
@Eugene. But am applying his style at runtime. You can check or uncheck that jus like a normal checkbox. I want to display the Text on that as Label Content. If I remove the style, the normal checkbox is coming along with its content.like: checkbox BreakFastI need a breakfast on top of that checkbox as Label's content.
Tarun
It's no matter when you apply style, control template is wrong. The checkmark has to be on the left side, label content has to be put on other free space. http://msdn.microsoft.com/en-us/library/ms752319(VS.85).aspx By this link provided CheckBox style and corresponding control template. Check the layout of you controltemplate and given in that example. It helps you to find out, why your checkbox has such strange behaviour.
Eugene Cheverda
A: 

It sounds to me like your designer forgot to include a <ContentPresenter/> in his checkbox template. If there is no ContentPresenter, the text you add as a comment will never be shown.

Here is an example of a custom CheckBox ControlTemplate that includes the required ContentPresenter:

<ControlTemplate TargetType="{x:Type CheckBox}">
  <DockPanel>
    <Border BorderThickness="1" BorderBrush="Black">
      <Path x:Name="check" Width="10" Height="10"
            Data=".... data for checkmark in checkbox ..." />
    </Border>
    <ContentPresenter/>
  </DockPanel>
  <ControlTemplate.Triggers>
    <Trigger ... trigger for changing checkmark ... />
  </ControlTemplate.Triggers>
</ControlTemplate>
Ray Burns