사각형의 그리드를 쓰려고하는데, 오브젝트의 색상을 변경합니다.WPF 직사각형 컬러 바인딩
private void Window_Loaded(object sender, RoutedEventArgs e)
{
for (int i = 0; i < size; i++)
{
main_grid.ColumnDefinitions.Add(new ColumnDefinition());
main_grid.RowDefinitions.Add(new RowDefinition());
}
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
cells[i, j] = new Cell { state = false, col = false };
Rectangle rect = new Rectangle();
Grid.SetColumn(rect, j);
Grid.SetRow(rect, i);
rect.Fill = Brushes.Orange;
rect.DataContext = cells[i, j];
rect.SetBinding(OpacityProperty, "ev_opacity");
Binding binding = new Binding("ev_col");
binding.Converter = new BooleanToBrushConverter();
rect.SetBinding(Rectangle.FillProperty, binding);
main_grid.Children.Add(rect);
}
}
setupTimer();
}
col과 관련하여 사각형의 색을 설정하는 방법은 무엇입니까? (f.e : 참 - 거짓, 검은 색 - 흰색)
셀 클래스 :
class Cell : INotifyPropertyChanged
{
private bool _state;
private bool _Col;
public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler PropertyChanged2;
public bool Col; //to set color
{
get
{
return _Col;
}
set
{
_Col = value;
if (PropertyChanged2 != null)
{
PropertyChanged2(this, new PropertyChangedEventArgs("event2"));
};
}
}
public bool state //to set opacity
{
get
{
return _state;
}
set
{
_state = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("ev_opacity"));
};
}
}
public static implicit operator int(Komorka c)
{
return Convert.ToInt32(c.state);
}
}
편집 : 가 작동하지 않습니다이 코드 - 내가 그리드를 클릭하면 실행 아무것도 후 일.
이 답변에서 클릭 이벤트를 어떻게 해결했는지는 분명하지 않습니다. –