views:

505

answers:

1

I am attempting to create a sukodu (like crossword) player in WPF, and I realize that I have a whole bunch of controls that will need to know the sudoku grid to function.

Because of this, I think the Sudoku Grid object would be a good candidate to create a dependency property. I am about to start the work, but I have some lingering questions:

  1. Who should own the SudokuGrid dependency property? I am thinking the main window UI element should.

  2. Should I set it as a shared dependency property, where all user controls that represent a part of a sudoku grid simply add themselves to the property via .AddOwner() method?

OR

Set it up as an attached property, defined at the main window, and allow child user controls to set up accordingly?

I don't really want child controls to be allowed to set their own grid property value though, so at this time I am leaning towards shared dependency property, but I am not sure it does what I think it does.

Ultimately what I want is one property where if it's set on a parent UI element, all children UI elements that knows about the property will share the same value, overriding any prior value / setting. Does shared dependency do that?

I know it's a bit long winded, but any help would be much appreciated!

+1  A: 

I think what you want is an attached property with the Inherits FrameworkPropertyOption. That we every control that wants to know about the grid can just find the grid by getting the value of the attached property (assuming it is set higher up in the tree). This article goes over attached properties and how to set them up.

Alternativly you might like to try out the Model View View-Model (MVVM) pattern and implement the Sudoku grid as a view-model class which each cell being a ceperate view-model class. That way the whole sudoku puzzel is completly seperate from the UI and the UI can just bind to it using appropriate data templates.

For more info on the MVVM pattern se the following: http://www.codeproject.com/KB/WPF/MVCtoUnitTestinWPF.aspx http://blogs.msdn.com/johngossman/archive/2005/10/08/478683.aspx

Caleb Vear