"WaferMap"이라는 클래스를 사용하여 자체 캔버스에 사각형을 그립니다. 기본보기에도 캔버스가 있습니다. WaferMap 클래스의 캔버스 내용을 GUI의 캔버스에 바인딩 할 수 있어야합니다. 이 작업을 수행하는 가장 좋은 방법은 무엇입니까?캔버스를 WPF로 캔버스에 바인딩
내가 지금하고있는 방식은 WaferMap 클래스에서 캔버스를 만든 다음 캔버스의 ContentPresenter 속성을 사용하여 GUI에서 캔버스에 바인딩하는 것입니다.
WaferMap 클래스 : 여기
public class WaferMap : ViewModelBase
{
#region Fields
protected const int rows = 23;
protected const int cols = 23;
protected int currentRow;
protected int currentCol;
protected DiePrint diePrint;
protected List<BlueTape> blueTapeList;
protected Canvas canvasToMap;
#endregion
#region Constructor
public WaferMap(List<BlueTape> btList)
{
blueTapeList = new List<BlueTape>();
blueTapeList = btList;
}
#endregion
#region Properties
public Canvas WaferMapCanvas
{
get
{
return canvasToMap;
}
}
public List<BlueTape> BlueTapeList
{
get
{
return blueTapeList;
}
}
#endregion
#region Methods
public void DrawWaferMap()
{
if (blueTapeList.Count > 0)
{
canvasToMap = new Canvas();
foreach (BlueTape bt in blueTapeList)
{
if (bt.DiePrintList.Count > 0)
{
foreach (DiePrint print in bt.DiePrintList)
{
// Create a new DiePrintRectangle and get its
// row and column coordinates
DiePrintRectangle diePrintRect = new DiePrintRectangle(print);
// Add the print to the canvas
canvasToMap.Children.Add(diePrintRect);
// Set the properties
Thickness margin = new Thickness(0);
diePrintRect.Margin = margin;
diePrintRect.Height = 25;
diePrintRect.Width = diePrintRect.Height;
diePrintRect.HorizontalAlignment = HorizontalAlignment.Left;
diePrintRect.VerticalAlignment = VerticalAlignment.Top;
currentCol = Convert.ToInt32(print.Col * diePrintRect.Height);
currentRow = Convert.ToInt32(print.Row * diePrintRect.Height);
print.MapCol = currentCol;
print.MapRow = currentRow;
Canvas.SetLeft(diePrintRect, currentCol);
Canvas.SetTop(diePrintRect, currentRow);
// Get the color of the print fill and stroke
//diePrintRect.Stroke = GetDiePrintColor(bt);
diePrintRect.StrokeThickness = 12;
diePrintRect.Stroke = GetDiePrintColor(bt);
diePrintRect.Fill = Brushes.Transparent;
diePrintRect.MouseDown += diePrintRect_MouseDown;
diePrintRect.MouseEnter += diePrintRect_MouseEnter;
}
}
}
}
}
}
그리고 내 XAML입니다 :
<DockPanel>
<Canvas Name="mapCanvas">
<ContentPresenter Content="{Binding WaferMap}"/>
</Canvas>
</DockPanel>
그리고 뒤에있는 코드 :
참고 :이 설정을위한이 바인딩을 디버깅합니다. "btnDoStuff"버튼이 클릭되면 GUI에서 캔버스의 datacontext를 설정합니다.
public partial class WaferTrackerWindow : Window
{
WaferTrackerWindowViewModel wtw;
public WaferTrackerWindow()
{
InitializeComponent();
SelectWaferButtonViewModel swbv = new SelectWaferButtonViewModel();
wtw = new WaferTrackerWindowViewModel(tvwWaferList, txtFilter);
wtw.SelectWaferButtonViewModel = swbv;
tvwDockPanel.DataContext = wtw.SelectWaferButtonViewModel;
DataContext = wtw;
btnChooseWafer.DataContext = wtw;
btnSelectWafer.DataContext = wtw;
btnExit.DataContext = wtw;
tbkWafer.DataContext = wtw;
btnDoStuff.Click += btnDoStuff_Click;
}
private void btnDoStuff_Click(object sender, RoutedEventArgs e)
{
mapCanvas.DataContext = wtw.WaferMap.WaferMapCanvas;
}
무엇인가의 이유로이 기능이 작동하지 않습니다. 어떤 도움이라도 대단히 감사하겠습니다.
클래스에서 캔버스를 만들고보기에서 캔버스에 바인딩하려고하는 것보다 더 좋은 방법이 있습니까?
고맙습니다.
아마도 바인딩은 WaferMapCanvas 속성에 있어야합니다 ... 실수로 클래스 이름 WaferMap을 사용한 것처럼 보입니다. –