Set button content in a label (custom control)

Posted by user1881207 on Stack Overflow See other posts from Stack Overflow or by user1881207
Published on 2012-12-06T04:30:38Z Indexed on 2012/12/06 5:04 UTC
Read the original article Hit count: 267

Filed under:
|
|

Instead of voting negative this question, answer to tell me what's wrong!

I want to set the Button Content in a label in the custom control, because when I use it, the Content property is not visible and the button is empty (no text).

<Button x:Class="WpfApplication1.UserControl1"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="35" d:DesignWidth="273" Content="Button">
<Button.Template>
    <ControlTemplate>
        <Grid>
            <Rectangle Name="rGridBack" StrokeThickness="1">
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FF4D4D4D" Offset="1" />
                        <GradientStop Color="#FF404040" Offset="0" />
                    </LinearGradientBrush>
                </Rectangle.Fill>
                <Rectangle.Stroke>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FF4F4F4F" Offset="0" />
                        <GradientStop Color="#FF5B5B5B" Offset="1" />
                    </LinearGradientBrush>
                </Rectangle.Stroke>
            </Rectangle>
            <Rectangle Fill="#FF1E1E1E" Margin="1,1,1,1" Name="rThickness" />
            <Rectangle Margin="2,2,2,2" Name="rGridTop" StrokeThickness="1">
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FF68686C" Offset="0" />
                        <GradientStop Color="#FF474747" Offset="1" />
                    </LinearGradientBrush>
                </Rectangle.Fill>
                <Rectangle.Stroke>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FF7F7F7F" Offset="0" />
                        <GradientStop Color="#FF575757" Offset="1" />
                    </LinearGradientBrush>
                </Rectangle.Stroke>
            </Rectangle>
   <!--This label is where I want to set the Button.Content property-->
            <Label FontWeight="Normal" Foreground="White" HorizontalContentAlignment="Center" Name="tblckStep1Desc" Padding="0" VerticalContentAlignment="Center">
                <Label.Effect>
                    <DropShadowEffect BlurRadius="2" Color="Black" Direction="330" Opacity="0.7" ShadowDepth="1.5" />
                </Label.Effect>
            </Label>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="Button.Content" Value="">
                <Setter Property="Content" TargetName="tblckStep1Desc">
                </Setter>
            </Trigger>
            <Trigger Property="UIElement.IsMouseOver" Value="True">
                <Setter Property="Shape.Fill" TargetName="rGridTop">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF838383" Offset="0" />
                            <GradientStop Color="#FF545454" Offset="1" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Shape.Stroke" TargetName="rGridTop">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF595959" Offset="1" />
                            <GradientStop Color="#FF929292" Offset="0" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Shape.Stroke" TargetName="rGridBack">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF414141" Offset="0" />
                            <GradientStop Color="#FF565656" Offset="1" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Shape.Fill" TargetName="rThickness">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF181818" Offset="1" />
                            <GradientStop Color="#FF181818" Offset="0" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="UIElement.IsEnabled" Value="False">
                <Setter Property="Shape.Fill" TargetName="rGridTop">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF68686C" Offset="0" />
                            <GradientStop Color="#FF474747" Offset="1" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Shape.Stroke" TargetName="rGridTop">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF7F7F7F" Offset="0" />
                            <GradientStop Color="#FF575757" Offset="1" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Shape.Stroke" TargetName="rGridBack">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF4F4F4F" Offset="0" />
                            <GradientStop Color="#FF5B5B5B" Offset="1" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Shape.Fill" TargetName="rThickness">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF1E1E1E" Offset="1" />
                            <GradientStop Color="#FF1E1E1E" Offset="0" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Control.Foreground" TargetName="tblckStep1Desc">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF898989" Offset="1" />
                            <GradientStop Color="#FF898989" Offset="0" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="ButtonBase.IsPressed" Value="True">
                <Setter Property="Shape.Fill" TargetName="rGridTop">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF313131" Offset="1" />
                            <GradientStop Color="#FF2E2E2E" Offset="0" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Shape.Stroke" TargetName="rGridTop">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF1F1F1F" Offset="1" />
                            <GradientStop Color="#FF1F1F1F" Offset="0" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Shape.Stroke" TargetName="rGridBack">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF414141" Offset="1" />
                            <GradientStop Color="#FF565656" Offset="0" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Shape.Fill" TargetName="rThickness">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF0C0C0C" Offset="1" />
                            <GradientStop Color="#FF0C0C0C" Offset="0" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
</Button.Template>

The button is based on Adobe CS5 suite on dialog forms, because a lot of code.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf