2010-05-31 2 views
0

내 문제는 다음과 같습니다. FollowImageControl이라는 다른 UC가 포함 된 UC라는 프로필이 있습니다.Dependencyproperty에로드시 값이 없음

내 Profile.xaml에서 FollowerId라는 FollowImageControl의 속성을 Profile.xaml.cs의 CurrentUserId에 선언적으로 바인딩합니다. 문제는 CurrentUserId가 Profile.xaml.cs에 할당되었다는 것입니다. Profile.xaml 코드 숨김.

이것은 처음에 FollowerId를 얻지 못했음을 의미합니다. I는 FollowImageControl.xaml.cs 이러한 방법을 가지고

public static readonly DependencyProperty _followUserId = 
        DependencyProperty.Register("FollowUserId", typeof(Guid), typeof(FollowImageControl), null); 
    public Guid FollowUserId 
    { 
     get { return (Guid)GetValue(_followUserId); } 
     set { SetValue(_followUserId, value); } 
    } 
    public FollowImageControl() 
    { 
     // Required to initialize variables 
     InitializeComponent(); 
     LoggedInUserId = WebContext.Current.User.UserId; 
     var ctx = new NotesDomainContext(); 
     if (ctx.IsFollowingUser(LoggedInUserId, FollowUserId).Value) SwitchToDelete.Begin(); 
    } 


    private void AddImg_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
    { 
     if (LoggedInUserId != FollowUserId) 
     { 
      var ctx = new NotesDomainContext(); 
      ctx.FollowUser(FollowUserId, LoggedInUserId); 
      ctx.SubmitChanges(); 
     } 
    } 

이상한 일 것을 나는 FollowImageControl에서 FollowerUserId()가 0 인 중단을 삽입하지만 AddImg_MouseLeftButtonDown의 값을 가지며, 때 그 값을 설정하는 논리가 없습니다. 방법이있다???

<internalCtrl:FollowImageControl FollowUserId="{Binding ElementName=ProfileCtrl, Path=CurrentUserId}" /> 

CurrentUserId가 설정되는 것을 특징으로하는이 profile.xaml.cs 내 생성자

내이 profile.xaml에서 구속력 : 여기

조금 더 코드 정보입니다 public static readonly DependencyProperty _CurrentUserId =

DependencyProperty.Register("CurrentUserId", typeof(Guid), typeof(Profile), null); 
     public Guid CurrentUserId 
     { 
      get { return (Guid)GetValue(_CurrentUserId); } 
      set { SetValue(_CurrentUserId, value); } 
     } 

public Profile(Guid UserId) { 
      CurrentUserId = UserId; 
      InitializeComponent(); 
      Loaded += new RoutedEventHandler(Profile_Loaded); 
     } 

나는 FollowerId가 아무런 가치가 없다는 것을 매우 당황 스럽다. 그리고 그 다음으로는 코드 숨김의 가치를 변경하지 않고도 그 권리가있다.

답변

0

FollowImageControl 생성자에서 중단 점을 어디에 설정 했습니까? InitializeComponent() 호출 전에 설정 한 경우 InitializeComponent()이 모든 XAML을 실행하기 때문에 이는 정상적인 동작입니다. 즉, 바인딩이이 메서드에서 만들어 지므로 InitializeComponent()이 호출되었지만 전에는 값이 없어야합니다. 물론 생성자가 완료된 후에 AddImg_MouseLeftButtonDown이 호출되므로 InitializeComponent()도 호출되었습니다.

+0

initializecomponent() 다음에 중단 점을 설정합니다. FollowerId에 값을 할당하지 않고 전체 생성자 코드를 실행합니다. 귀하의 관심을 가져 주셔서 감사합니다 :) – Jakob

+0

프로필에 포함 된 FollowImageControl UC가 currentid 값이 설정되기 전에로드되어 문제를 일으키고 있다고 생각하지만 어떻게 값을 전달할 수 있습니까? – Jakob

+0

이 문제는 완전히 관련이없는 것으로 판명되었지만 대부분의 경우 귀하의 대답이 올바른 것이라고 확신하므로 귀하의 답변에 플래그가 표시됩니다 – Jakob