2009-09-23 56 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

相關問題