내 문제는 재현하기가 쉽습니다. 뷰 모델을 사용하여 처음부터 프로젝트를 만들었습니다. "나이"속성의 설정자에서 볼 수있는 것처럼 간단한 논리가 있습니다. 에서 MainPage.xaml디버거가 연결되었을 때 Silverlight 5가 해당 설정자의 논리가있는 속성에 바인딩되지 않습니다.
<Grid x:Name="LayoutRoot" Background="White">
<TextBox
Text="{Binding Path=Age, Mode=TwoWay}"
HorizontalAlignment="Left"
Width="100"
Height="25"/>
<TextBlock
Text="{Binding Path=Age, Mode=OneWay}"
HorizontalAlignment="Right"
Width="100"
Height="25"/>
</Grid>
그리고 MainPage.xaml.cs를 단순히보기 모델의 인스턴스와의 DataContext로 설정에서
public class MainViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private int age;
public int Age
{
get
{
return age;
}
set
{
/*Age has to be over 18* - a simple condition in the setter*/
age = value;
if(age <= 18)
age = 18;
OnPropertyChanged("Age");
}
}
public MainViewModel(int age)
{
this.Age = age;
}
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
. 텍스트 상자에 바인딩 값 "5"를 눌러 탭을 (삽입 :
public partial class MainPage : UserControl
{
private MainViewModel mvm;
public MainPage()
{
InitializeComponent();
mvm = new MainViewModel(20);
this.DataContext = mvm;
}
}
은이 코드는 텍스트 상자에 입력 한 값보다 낮은 18 시나리오 인 경우 18 시대를 설정 제한 할 것으로 예상 TextBox에 포커스가 없어야 함)
사례 1 : 디버거가 연결됨> TextBox 값이 "5"이고 TextBlock 값이 "18"이됩니다. - 잘못된
사례 2 : 디버거가 부착되지 않습니다 => 텍스트 상자의 값은 "18"입니다 및 TextBlock의 값은 "18"입니다 - 올바른
디버거가 연결되었을 때대로 작동하지 않습니다 바인딩 것 같다 속성 값의 업데이트를 트리거 한 객체에서 예상됩니다. 우리가 바인딩하는 속성에 setter 또는 getter에 대한 논리가있는 경우에만 발생합니다.
SL5에서 변경된 사항이 있으며 설정자의 논리가 더 이상 허용되지 않습니까?
구성 : 으로 VisualStudio 2010 SP1 SL 5 도구 5.1.30214.0 SL5 SDK를 5.0.61118.0 IE 10 사람이 대답에 관심이 있다면