2009-09-23 30 views
1
<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; 
     } 
    } 
+0

那是什么:)? – Anvaka 2009-09-23 15:59:52

回答

1

我不太清楚你在问什么。 :)但是,如果我能猜出你是什么后... 你可以在样式使用一个简单的属性触发这样的:

<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> 

以上假设,当然,一个枚举依赖项属性,WarningLevel在UserControl1上。

+0

很高兴帮助和高兴地猜到你在找什么。 – cplotts 2009-09-25 14:38:51

相关问题