방법: 코드를 사용하여 Silverlight 화면 수정

Visual Studio LightSwitch를 사용하면 디자이너 및 도구 창을 사용하여 다양한 화면 관련 디자인 작업을 수행할 수 있습니다.하지만 사용자가 코드를 사용하여 수행하려는 특정 작업이 있을 수 있습니다.이 항목에서는 화면 개체 모델을 사용하여 일반적인 화면 관련 디자인 작업 집합을 수행하는 방법을 보여 줍니다.응용 프로그램에서 코드를 작성할 수 있는 위치에 대한 자세한 내용은 다음 항목을 참조하십시오.

Visual Studio LightSwitch에서의 코드 작성에 대한 일반적 지침은 LightSwitch에서 코드 작성를 참조하십시오.

일반 작업

다음 목록에서는 화면 개체 모델을 사용하여 수행할 수 있는 일반적인 데이터 관련 작업에 대해 설명합니다.

  • 컨트롤 숨기기, 읽기 전용으로 설정 또는 비활성화

컨트롤 숨기기, 읽기 전용으로 설정 또는 비활성화

코드를 사용하여 화면에 컨트롤을 표시하거나 숨길 수 있습니다.컨트롤의 읽기 전용 또는 비활성 여부를 지정할 수 있습니다.

다음 예제에서는 회사 이름이 Coho Winery인 경우 데이터 그리드에서 회사 이름을 숨깁니다.이 예제에서는 또한 컨트롤을 읽기 전용으로 만들어서 뷰어로 컨트롤에 텍스트를 입력함으로써 회사 이름을 수정하지 못하게 합니다.

Private Sub FindControlInList()
    Dim index As Integer = 0

    For Each cust As Customer In Customers

        If cust.CompanyName = "Great Lakes Food Market" Then
            With FindControlInCollection("CompanyName", Customers(index))
                .IsVisible = False
                .IsReadOnly = True
            End With

        End If
        index = index + 1
    Next
End Sub
private void FindControlInList()
{
    int index = 0;

    foreach (Customer cust in this.Customers)
    {
        if (cust.CompanyName == "Great Lakes Food Market")
        {
            this.FindControlInCollection("CompanyName",
            this.Customers.ElementAt(index)).IsVisible = false;
            this.FindControlInCollection("CompanyName",
            this.Customers.ElementAt(index)).IsReadOnly = true;
        }

        index++;
    }

}

다음 예제는 선택한 항목의 회사 이름이 Coho Winery인 경우 화면에서 자세히 보기로 볼 때 회사 이름을 숨깁니다.이 예제는 또한 사용자가 Coho Winery에서 일하는 고객을 삭제할 수 없도록 삭제 단추를 비활성화합니다.

Private Sub Customers_SelectionChanged()
    FindControl("Customers_DeleteSelected").IsEnabled = True

    If Me.Customers.SelectedItem.CompanyName = "Great Lakes Food Market" Then

        FindControl("CompanyName1").IsVisible = False
        FindControl("Customers_DeleteSelected").IsEnabled = False

    End If

End Sub
partial void Customers_SelectionChanged()
{
    this.FindControl("Customers_DeleteSelected").IsEnabled = true;

    if (this.Customers.SelectedItem.CompanyName == "Great Lakes Food Market")
    {
        this.FindControl("CompanyName1").IsVisible = false;
        this.FindControl("Customers_DeleteSelected").IsEnabled = false;
    }
}

참고 항목

작업

방법: Silverlight 화면 이벤트 처리

개념

LightSwitch에서 코드 작성

코드를 사용하여 데이터 관련 작업 수행

기타 리소스

화면: 응용 프로그램의 사용자 인터페이스