source

행 및 열 인덱스로 WPF 그리드의 제어에 프로그래밍 방식으로 액세스하는 방법은 무엇입니까?

nicesource 2023. 4. 19. 23:15
반응형

행 및 열 인덱스로 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

반응형