반응형
행 및 열 인덱스로 WPF 그리드의 제어에 프로그래밍 방식으로 액세스하는 방법은 무엇입니까?
제어장치를 WPF 그리드에 추가한 후 행 및/또는 열 인덱스로 프로그래밍 방식으로 액세스할 수 있는 방법이 있습니까?다음과 같은 것들이 있습니다.
var myControl = (object)MyGrid.GetChild(int row, int column);
...어디에GetChild
내가 갖고 싶었던 방법이야!
기본 제공 방법은 없지만 Children 컬렉션을 보면 쉽게 할 수 있습니다.
myGrid.Children
.Cast<UIElement>()
.First(e => Grid.GetRow(e) == row && Grid.GetColumn(e) == column);
int rowIndex = Grid.GetRow(myButton);
RowDefinition rowDef = myGrid.RowDefinitions[rowIndex];
그리드 객체의 Children 속성은 (Panel 클래스의) 그리드의 모든 자식 컬렉션을 제공합니다.
그리드의 좌표를 취득하기 위해서는 그리드 클래스의 정적 메서드(GetRow() 및 GetColumn())를 확인합니다.
그것이 당신을 올바른 방향으로 이끌기를 바랍니다.
시스템:Windows:: 컨트롤::그리드^ myGrid = nullptr; 시스템:Windows:: 컨트롤::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;
}
}
그리드 열/행의 이름을 지정할 수 있습니다.
<Grid x:Name="MainGridBackground" Grid.Column="0"/>
호출하고 ""를 사용하여 프로그래밍 방식으로 액세스합니다.
MainGridBackground.Background = canvasUCInstance.rectanglePreview.Fill;
언급URL : https://stackoverflow.com/questions/1511722/how-to-programmatically-access-control-in-wpf-grid-by-row-and-column-index
반응형
'source' 카테고리의 다른 글
FormBuilder 컨트롤의 수동 값 설정 (0) | 2023.04.24 |
---|---|
왼쪽 조인 포함 상위 1위 (0) | 2023.04.19 |
커밋 메시지로 Git 저장소를 검색하는 방법 (0) | 2023.04.19 |
SwiftUI - 뷰에 하드코딩된 네비게이션을 피하는 방법 (0) | 2023.04.19 |
기본 스타일에서 스타일 상속 (0) | 2023.04.19 |