Моя проблема в том, что у меня есть UC с именем profile, который содержит другой UC с именем FollowImageControl.
В моем Profile.xaml я декларативно связываю свойство FollowImageControl, которое называется FollowerId, с CurrentUserId из Profile.xaml.cs. Проблема в том, что я CurrentUserId назначен в Profile.xaml.cs; кодовый профиль Profile.xaml.
Это означает, что я изначально не получаю FollowerId. У меня есть эти методы в 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();
}
}
странная вещь , что когда я вставляю точки останова, FollowerUserId в FollowImageControl () равен 0, но он имеет значение в AddImg_MouseLeftButtonDown, и между ними нет логики, которая задает его значение. Как это ???
Вот еще немного информации о коде:
Это моя привязка от profile.xaml
<internalCtrl:FollowImageControl FollowUserId="{Binding ElementName=ProfileCtrl, Path=CurrentUserId}" />
это мой конструктор в profile.xaml.cs , в котором установлен CurrentUserId
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 не имеет значения, а в следующую - право, без меня, изменив значение в коде позади.