Hello,
Welcome to Microsoft Q&A!
As you mentioned, if you want to implement the two-way binding, you could declare a class which contains properties and implements INotifyPropertyChanged interface. After that, import a viewmodel which contains the class to the Mainpage and implement binding. It is better to use viewmodel to achieve code separation and below are the detailed steps about it.
1.Create an IDL file named BookSku to store the binding source in your C++/WinRT project
BookSku.idl
namespace DataBindingSample
{
runtimeclass BookSku : Windows.UI.Xaml.Data.INotifyPropertyChanged
{
String Title;
}
}
2.Implement BookSku with a struct that has the member variable you wish to expose and update
3.Declare and implement BookstoreViewModel to contain the BookSku and consolidate everything from the initial struct that can call those methods and return it to the MainPage
4.Add a property of BookstoreViewModel to MainPage with a “import” statement
MainPage.idl
import "BookstoreViewModel.idl";
namespace Bookstore
{
runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
{
MainPage();
BookstoreViewModel MainViewModel{ get; };
}
}
5.Bind the TextBox to the Title property with TwoWay mode.
<TextBox x:Name="box" Text="{x:Bind MainViewModel.BookSku.Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
For more detailed information, you can refer to the document and here is a simple sample that I created you can also check it.