Get Grid.Column property from sender
I'm pretty new around WP/Visual C# and I'm currently making a project that involves a grid (with cols and rows) filled 100+ buttons, I have created a general function for all them, but I do need to know which one was actually pressed, I figured out the "Grid.Column" "Grid.Row" properties in the buttons, and I use them to place in the right spot each button.
Property:
<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Background="{x:Null}" Padding="0" Grid.Row="1" Grid.Column="1"/>
But what I can't do is to get this properties from my button code, I have tried this:
int rows = ((Button)sender).Grid.rows;
Which gives me this error:
Error 1: 'System.Windows.Controls.Button' does not contain a definition for 'Grid' and no extension method 'Grid' accepting a first argument of type开发者_JS百科 'System.Windows.Controls.Button' could be found (are you missing a using directive or an assembly reference?) C:\Users\K\Documents\Visual Studio 2010\Projects\buscaminas\bus\MainPage.xaml.cs 71
Is there any solution? :D
It is called attached dependency property. You need to use the class, that declares them to access.
var row = Grid.GetRow((Button)sender);
var col = Grid.GetColumn((Button)sender);
精彩评论