그래서 App.xaml.cs에 정의 된 두 개의 전역 속성 인 Username과 CurrentView가 있으며 내보기에 바인딩되어 있습니다. 다른보기에 둘을 결합Xaml 바인딩이 Application.Current와 함께 작동하지 않습니다.
App.xaml.cs를
public partial class App : Application, INotifyPropertyChanged
{
public static object username;
public object Username { get { return username; } set { username = value; } }
public static Object currentView = new LoginView();
public object CurrentView
{
get { return currentView; }
set { currentView = value; }
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
그리고 임. MainView.xaml
<Page Content="{Binding CurrentView, Source={x:Static Application.Current}}">
</Page>
LoginView.xaml
<TextBox HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="165" Margin="218,159,0,0" Text="{Binding Path=Username, Source={x:Static Application.Current}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}" />
MAINVIEW 바인딩은 완벽하게 잘 작동한다. 그것은 내가 currentView를 app.xaml.cs에서 초기화 한 LoginView를 보여 주며 소스가 변경되면 변경됩니다.
그러나 LoginView에서 입력란에 바인딩 된 사용자 이름은 업데이트되지 않습니다. Cant가 문제를 파악하는 것 같습니다. Iv가 UpdateSourceTrigger를 PropertyChanged로 설정하면 업데이트해야합니다.
은 어떤 도움이 많이 주시면 감사합니다 :)
는
Iv가 문자열로 변경되었습니다. 아직 운이 없다 : ( 공개 정적 문자열 사용자 이름 공개 문자열 사용자 이름 {get {사용자 이름}} set {사용자 이름 = 값;}} –
업데이트 된 답변 확인 – AlexDrenea
Iv가 모든 모드에서 시도했으나 여전히 좋지는 않습니다. TwoWay에 그대로 두라. –