개체의 속성을 사용자 지정 컨트롤에 바인딩할 수 없습니다.

라이언 스튜어트

보기 모델에 바인딩된 콘텐츠 페이지가 있습니다.

보기 모델에서 주소를 새로 만들고 일부 데이터를 제공합니다.

Address = new Address
{
     UserId = Guid.NewGuid(),
     PrimaryAddress = true,
     Postcode = "G23 5HU",
     Street = "Smith Street",
     City = "Large City",
     PhoneNumber = "115151"
};

또한 콘텐츠 페이지에 AddressInfo 컨트롤이 있습니다.

 <controls:AddressInfo Address="{Binding Address}"></controls:AddressInfo>

여기 자체 컨트롤이 있습니다.

public partial class AddressInfo : ContentView
{
    public static readonly BindableProperty AddressProperty =
        BindableProperty.Create(nameof(Address), typeof(Address), typeof(AddressInfo), null);

    public Address Address
    {
        get { return (Address)GetValue(AddressProperty); }
        set { SetValue(AddressProperty, value); }
    }

    public AddressInfo()
    {
        InitializeComponent();
        Street.SetBinding(Label.TextProperty, new Binding(nameof(Address.Street), source: this));
        City.SetBinding(Label.TextProperty, new Binding(nameof(Address), source: this));
        PhoneNumber.SetBinding(Label.TextProperty, new Binding(nameof(Address), source: this));
        PostCode.SetBinding(Label.TextProperty, new Binding(nameof(Address), source: this));
    }

다음은 컨트롤 XAML입니다.

<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="TyreKlicker.XF.Core.Controls.AddressInfo">
<ContentView.Content>

    <StackLayout>
        <Label
                x:Name="Street"
                Text="{Binding Address.Street}" />
        <Label
                x:Name="City"
                Text="{Binding Address.City}" />
        <Label  Text="Hardcoded Text" ></Label>
        <Label
                x:Name="PostCode"
                Text="{Binding Address.Postcode}" />
        <Label
                x:Name="PhoneNumber"
                Text="{Binding Address.PhoneNumber}" />

        <Label x:Name="CardHeader"
                   Text="{Binding Header}"
                   TextColor="{StaticResource PrimaryDark}"
                   FontSize="Large" Margin="10,0,0,0" />

        <Button Clicked="Button_OnClicked"></Button>
    </StackLayout>
</ContentView.Content>

내가 그것을 실행할 때 나는 주소 속성을 볼 것으로 예상하지만 대신 하드 코딩 된 텍스트를 제외하고는 모두 비어 있습니다.

실행 중인 앱 사진

Button_OnClicked 이벤트를 중지하면 디버깅을 지원하기 위해 컨트롤에 버튼을 추가했습니다. 주소의 속성을 볼 수 있고 올바른 데이터가 있지만 목록에 표시되지 않습니다. 내가 뭘 잘못하고 있습니까?

주소 속성

라이언 스튜어트

Jason의 힌트 덕분에 AddressInfo 생성자와 비올라에서 다음 줄을 제거했습니다.

        //Street.SetBinding(Label.TextProperty, new Binding(nameof(Address.Street), source: this));
        //City.SetBinding(Label.TextProperty, new Binding(nameof(Address), source: this));
        //PhoneNumber.SetBinding(Label.TextProperty, new Binding(nameof(Address), source: this));
        //PostCode.SetBinding(Label.TextProperty, new Binding(nameof(Address), source: this));

도와 주셔서 감사합니다!

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

ListView의 UWP에서 사용자 지정 컨트롤을 사용하여 속성을 바인딩 할 수 없습니다.

다른 사용자 정의 컨트롤의 속성을 바인딩할 수 있습니까?

내 사용자 지정 컨트롤의 명령에 바인딩 할 수 없습니다.

ObservableCollection을 사용자 지정 컨트롤이 포함 된 listView에 바인딩 할 수 없습니다.

사용자 지정 컨트롤의 다른 속성에 속성 바인딩

wpf에서 부모 컨트롤의 속성에 바인딩 된 종속성 속성을 통해 xaml의 사용자 컨트롤 데이터 컨텍스트를 설정할 수 있습니까?

사용자 정의 컨트롤에서 명령을 어떻게 바인딩 할 수 있습니까?

열 개수 속성은 데이터 바인딩 된 datagridview 컨트롤에 설정할 수 없습니다. c #

한 컨트롤러 메서드에서 설정된 모델 속성의 속성을 다른 컨트롤러 메서드에서 사용할 수 없습니다.

사용자 지정 WPF 컨트롤에서 DataGrid 열의 가시성을 어떻게 바인딩 할 수 있습니까?

xml 조각 내의 컨트롤에 사용자 지정 속성을 어떻게 전달할 수 있습니까?

function()을 사용할 때 정의되지 않은 속성 '컨트롤'을 읽을 수 없습니다.

vm을 사용하여 범위에 바인딩 할 수 없습니다. 컨트롤러 / html의 표기법

사용자 정의 컨트롤의 속성을 부모 속성에 바인딩

각도 재질 모달 대화 상자에서 컨트롤러의 속성을 설정할 수 없습니다.

flex의 속성을 특정 값에 바인딩 할 수 없습니다.

사용자 지정 지시문 : 요소의 알려진 속성이 아니므로 지시문에 바인딩 할 수 없습니다.

내 사용자 지정 복합 컨트롤에 개체를 전달할 수 없습니다

ItemSource의 지정된 속성을 사용하도록 컨트롤의 속성 (DataTemplate 및 UserControl 내부에 있음)에 대한 바인딩을 어떻게 설정할 수 있습니까?

내 자신의 컨트롤에서 내부 컨트롤의 속성을 노출 할 수 없습니다.

사용자 지정 컨트롤의 종속성 속성에 바인딩

(Windows 10 UWP) PivotItem 컨트롤의 Header 속성을 Pivot 컨트롤의 사용자 지정 HeaderTemplate에 바인딩하는 방법은 무엇입니까?

VBA에서 사용자 정의 컨트롤을 실행할 때 개체가이 속성 오류를 지원하지 않습니다.

UWP 사용자 지정 컨트롤, 바인딩을 사용할 수 없음, x : Bind 만, 적응 방법?

내 사용자 정의 컨트롤에서 연결된 속성 바인딩이 실패했습니다.

ViewSettingsCustomItem 내에서 사용자 지정 컨트롤에 모델을 사용할 수 없습니다.

컨트롤러에 도착할 때 쿼리 문자열의 ViewModel 속성이 바인딩되지 않습니다.

사용자 지정 ContentView에 대한 바인딩 가능한 속성을 만들 수 없습니다.

사용자 정의 구조체의 속성을 사용할 수 없습니다

TOP 리스트

  1. 1

    Ionic 2 로더가 적시에 표시되지 않음

  2. 2

    JSoup javax.net.ssl.SSLHandshakeException : <url>과 일치하는 주체 대체 DNS 이름이 없습니다.

  3. 3

    std :: regex의 일관성없는 동작

  4. 4

    Xcode10 유효성 검사 : 이미지에 투명성이 없지만 여전히 수락되지 않습니까?

  5. 5

    java.lang.UnsatisfiedLinkError : 지정된 모듈을 찾을 수 없습니다

  6. 6

    rclone으로 원격 디렉토리의 모든 파일을 삭제하는 방법은 무엇입니까?

  7. 7

    상황에 맞는 메뉴 색상

  8. 8

    SMTPException : 전송 연결에서 데이터를 읽을 수 없음 : net_io_connectionclosed

  9. 9

    정점 셰이더에서 카메라에서 개체까지의 XY 거리

  10. 10

    Windows cmd를 통해 Anaconda 환경에서 Python 스크립트 실행

  11. 11

    다음 컨트롤이 추가되었지만 사용할 수 없습니다.

  12. 12

    C #에서 'System.DBNull'형식의 개체를 'System.String'형식으로 캐스팅 할 수 없습니다.

  13. 13

    JNDI를 사용하여 Spring Boot에서 다중 데이터 소스 구성

  14. 14

    Cassandra에서 버전이 지정된 계층의 효율적인 모델링

  15. 15

    복사 / 붙여 넣기 비활성화

  16. 16

    Android Kotlin은 다른 활동에서 함수를 호출합니다.

  17. 17

    Google Play Console에서 '예기치 않은 오류가 발생했습니다. 나중에 다시 시도해주세요. (7100000)'오류를 수정하는 방법은 무엇입니까?

  18. 18

    SQL Server-현명한 데이터 문제 받기

  19. 19

    Seaborn에서 축 제목 숨기기

  20. 20

    ArrayBufferLike의 typescript 정의의 깊은 의미

  21. 21

    Kubernetes Horizontal Pod Autoscaler (HPA) 테스트

뜨겁다태그

보관