Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:


why my Button Style not Show Button content?
Hello
I Create simply style for button and use ContentPresenter to display My Button Content.But buttoncontent not display.

HTML
<Style x:Key="btnStyle" TargetType="{x:Type Button}">
           <Setter Property="Template">
               <Setter.Value>
                   <ControlTemplate TargetType="{x:Type Button}" >
                       <Grid>

                            <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"  ContentSource="Content"/>

                           <Rectangle RadiusX="5" RadiusY="5">


                               <Rectangle.Fill>
                                   <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                       <GradientStop Color="#FF7C3030" Offset="0" />
                                       <GradientStop Color="#FF271D1D" Offset="1" />
                                       <GradientStop Color="#FF450404" Offset="0.484" />
                                   </LinearGradientBrush>
                               </Rectangle.Fill>

                           </Rectangle>

                       </Grid>

                   </ControlTemplate>
               </Setter.Value>
           </Setter>
           <Setter Property="Foreground" Value="White"/>
       </Style>






HTML
 <Button Grid.Row="1" Grid.Column="1"
 Content="ShowWindow" Style="{StaticResource btnStyle}" 
Foreground="White" FontSize="20"/>
Posted
Comments
Richard MacCutchan 1-Apr-12 9:10am    
Where in your resources did you put the Style entry?
loger21 1-Apr-12 11:17am    
you can View Complet SourceCode here.

1 solution

Put your ContentPresenter after the rectangle, as the rectangle will overwrite it, as its zindex will be implied higher.
 
Share this answer
 
Comments
loger21 1-Apr-12 12:20pm    
thanks for solution.the problems is solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900