Jak programować kontrolę dostępu w siatce WPF według indeksu wierszy i kolumn?
Po dodaniu kontrolek do siatki WPF, czy istnieje sposób na programowy dostęp do nich za pomocą indeksu wierszy i / lub kolumn? Coś w stylu:
var myControl = (object)MyGrid.GetChild(int row, int column);
... gdzie {[1] } jest metoda, którą chciałbym mieć!
5 answers
Nie ma wbudowanej metody na to, ale możesz to łatwo zrobić, patrząc w kolekcji dzieci:
myGrid.Children
.Cast<UIElement>()
.First(e => Grid.GetRow(e) == row && Grid.GetColumn(e) == column);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-10-02 21:12:19
Ta odpowiedź pomoże ci
int rowIndex = Grid.GetRow(myButton);
RowDefinition rowDef = myGrid.RowDefinitions[rowIndex];
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:26:37
Właściwość Children obiektu grid da ci kolekcję wszystkich potomków siatki (z klasy Panel).
Jeśli chodzi o pobieranie współrzędnych w siatce, spójrz na statyczne metody w klasie Grid (GetRow () & GetColumn()).
Mam nadzieję, że to skieruje cię w dobrym kierunku.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-10-02 21:17:38
System:: Windows:: Controls:: Grid^ myGrid = nullptr; System:: Windows:: Controls:: UserControl^ pUserControl = nullptr;
myGrid = m_DlgOwnedObjAdmin->GrdProperties;
if (myGrid->Children->Count > 0)
{
pUserControl = (System::Windows::Controls::UserControl^)myGrid->Children->default[0];
if (pUserControl != nullptr)
{
if (bValue == true)
pUserControl->Visibility = System::Windows::Visibility::Visible;
else
pUserControl->Visibility = System::Windows::Visibility::Collapsed;
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-13 04:56:16
Możesz po prostu nadać swoją kolumnę/wiersz siatki nazwę
<Grid x:Name="MainGridBackground" Grid.Column="0"/>
I uzyskać do niego dostęp programowo, wywołując go i używając "."
MainGridBackground.Background = canvasUCInstance.rectanglePreview.Fill;
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-08 21:33:09