Yanshof

Yanshof

  • NA
  • 27
  • 0

Why my checkbox override does not work ? ( Code attached )

Oct 13 2010 12:23 AM

I created 3 state check box -
The basic idia is simple -
if the checkbox is in normal state => show image1
if in press state => show image2
if in mouse over state => show image3

.
 
 
 

I try to create 3 state button. This control will will change the image on each of those 3 state ( normal, pressed, mouseOver ). The images of each state will be define as a property from the c# code ==> that mean i will be able to re-use this code and change the properties of the image source.

changinf images is done by binding the images to the code.
for some reason i dont see anything on the window when i using the control.
i dont see the images change, i dont see the control border and i dont know why.
 
attached the control code : because i realy dont know what wrong here ...
 
1. xaml:
 
<CheckBox x:Class="Controls.CheckBoxEx_"
             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" 
             Width="400" Height="400"
             d:DesignHeight="300" d:DesignWidth="300" >
    <CheckBox.Template>

        <ControlTemplate TargetType="{x:Type CheckBox}">

            <Grid>
                
                <Image x:Name="Normal"   Visibility="Visible" Source="{Binding NormalImp}" />
                <Image x:Name="Pressed"  Visibility="Hidden" Source="{Binding pressedImp}" />
                <Image x:Name="MouseOver" Visibility="Hidden" Source="{Binding MouseOverImp}" />
                
            </Grid>

            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="Normal" Property="Visibility" Value="Hidden"/>
                    <Setter TargetName="Pressed" Property="Visibility" Value="Hidden"/>
                    <Setter TargetName="MouseOver" Property="Visibility" Value="Visible"/>
                </Trigger>



                <Trigger Property="IsChecked" Value="True">
                    <Setter TargetName="Normal" Property="Visibility" Value="Hidden"/>
                    <Setter TargetName="Pressed" Property="Visibility" Value="Visible"/>
                    <Setter TargetName="MouseOver" Property="Visibility" Value="Hidden"/>
                </Trigger>

                <Trigger Property="IsChecked" Value="False">
                    <Setter TargetName="Normal" Property="Visibility" Value="Visible"/>
                    <Setter TargetName="Pressed" Property="Visibility" Value="Hidden"/>
                    <Setter TargetName="MouseOver" Property="Visibility" Value="Hidden"/>
                </Trigger>

            </ControlTemplate.Triggers>
        </ControlTemplate>

    </CheckBox.Template>

</CheckBox>

 

 
 
2. C# Code:
 
 

 
public partial class CheckBoxEx_ : CheckBox
    {
        public CheckBoxEx_()
        {
            InitializeComponent();
            this.DataContext = this;
        }

        #region Field

        public Image mouseOver;
        public Image pressed;
        public Image normal;

        #endregion

        #region Properties

        public Image MouseOverImg
        {
            get
            {
                return mouseOver;
            }

            set
            {
                mouseOver = value;
            }
        }

        public Image PressedImg
        {
            get
            {
                return pressed;
            }

            set
            {
                pressed = value;
            }
        }

        public Image NormalImg
        {
            get
            {
                return normal;
            }

            set
            {
                normal = value;
            }
        }

        #endregion 
    }

Answers (3)