Wpf – How to rise triggers for a usercontrol with its custom property?

wpf

<UserControl
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:local="clr-namespace:LayoutCreator"
 mc:Ignorable="d"
 x:Class="LayoutCreator.Cell"
 x:Name="UserControl" Width="100" Height="100">
    <Grid x:Name="LayoutRoot">
        <Border Background="#FFF2F0F0" x:Name="CellBorder" BorderThickness="4,4,4,4">
            <Rectangle Stroke="#FF000000" Width="Auto" Height="Auto" x:Name="ActualCell" Style="{DynamicResource RectangleStyle}" MouseLeftButtonDown="ActualCell_MouseLeftButtonDown" />
        </Border>
    </Grid>
    <UserControl.Resources>
        <Style  TargetType="{x:Type local:Cell}">
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="true">
                    <!--here i want to update the properties of Border and Rectangle-->
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
</UserControl>


public partial class Cell
    {

        public bool IsSelected
        {
            get { return (bool)GetValue(IsSelectedProperty); }
            set { SetValue(IsSelectedProperty, value); }
        }

        public static DependencyProperty IsSelectedProperty =
           DependencyProperty.Register("IsSelected", typeof(bool), typeof(Cell),
           new FrameworkPropertyMetadata(false));

        public bool IsBlocked
        {
            get { return (bool)GetValue(IsBlockedProperty); }
            set { SetValue(IsBlockedProperty, value); }
        }

        public static DependencyProperty IsBlockedProperty =
           DependencyProperty.Register("IsBlocked", typeof(bool), typeof(Cell),
           new FrameworkPropertyMetadata(false));



        public Cell()
        {
            this.InitializeComponent();
        }


        private int _RowPositon;

        public int RowPositon
        {
            get { return _RowPositon; }
            set { _RowPositon = value; }
        }
        private int _ColPosition;

        public int ColPosition
        {
            get { return _ColPosition; }
            set { _ColPosition = value; }
        }

        private void ActualCell_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.IsSelected = !this.IsSelected;
        }
    }

Best Solution

I'm not quite sure what you are asking. :) But, if I could guess what you are after ... you could use a simple property trigger in a style like this:

<Style x:Key="userControlStyle" TargetType="{x:Type local:UserControl1}">
    <Style.Triggers>
        <Trigger Property="WarningLevel" Value="AllClear">
            <Setter Property="BorderBrush" Value="DarkGreen"/>
        </Trigger>
        <Trigger Property="WarningLevel" Value="Warning">
            <Setter Property="BorderBrush" Value="Yellow"/>
        </Trigger>
        <Trigger Property="WarningLevel" Value="Danger">
            <Setter Property="BorderBrush" Value="DarkRed"/>
        </Trigger>
    </Style.Triggers>
</Style>

The above assumes, of course, a enum dependency property, WarningLevel on UserControl1.

Related Question