簡體   English   中英

從發件人獲取Grid.Column屬性

[英]Get Grid.Column property from sender

我是WP / Visual C#的新手,目前正在制作一個包含100個以上按鈕的網格(帶有列和行)的項目,我為所有這些按鈕創建了一個通用函數,但我確實需要知道實際上是一個按鈕,我找出了按鈕中的“ Grid.Column”和“ Grid.Row”屬性,然后使用它們將每個按鈕放在正確的位置。

屬性:

<Button Content="" Margin="-12,-12,0,-13" Width="69" HorizontalAlignment="Left" BorderThickness="2" Background="{x:Null}" Padding="0" Grid.Row="1" Grid.Column="1"/>

但是我不能做的就是從按鈕代碼中獲得此屬性,我已經嘗試過了:

int rows = ((Button)sender).Grid.rows;

這給了我這個錯誤:

Error 1: 'System.Windows.Controls.Button' does not contain a definition for 'Grid' and no extension method 'Grid' accepting a first argument of type '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

有什么解決辦法嗎? :D

它稱為附加依賴項屬性。 您需要使用聲明其訪問權限的類。

var row = Grid.GetRow((Button)sender);
var col = Grid.GetColumn((Button)sender);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM