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

답변

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

관련 문제