microsoft / TemplateStudio

Template Studio accelerates the creation of new WinUI 3, WPF, and UWP apps using a wizard-based experience.
Other
2.65k stars 459 forks source link

`x:Bind` Not Working? #4735

Closed myokeeh closed 2 months ago

myokeeh commented 2 months ago

Describe the bug

I just created a Menu Bar WinUI project. All Nuget packages updated.

MainPage.xaml

        <TextBlock Grid.Row="0"
                   x:Uid="Main_Title"
                   Style="{StaticResource PageTitleStyle}" />
        <!--line below added for testing-->
        <TextBlock><Run Text="{x:Bind ViewModel.Busytext1, Mode=OneWay}"></Run></TextBlock>

MainViewModel.cs:

    [ObservableProperty]
    public string _busytext1 = "test";

To Reproduce

  1. Create new Menu Bar WinUI Template Studio project
  2. Add xaml code above to MainPage.xaml
  3. Add code above to MainViewModel.cs.
  4. Set Property Busytext1 to some text via code behind.
  5. UI isn't updated. Remains as "text" value

Additional context

I'm coming from UWP and used Windows Template Studio. I didn't run into issues like this.

I tried adding/setting datacontext or adding similar xaml code that referenced the viewmodel, but can't get binding to work.

Binding works on load, but subsequent attempts to set the Properties that are bound don't work.

Applies to the following platforms:

About your setup

myokeeh commented 2 months ago

This was related to a question I already asked previously: https://github.com/microsoft/TemplateStudio/discussions/4585#discussioncomment-3322099

Changing Transient to Singleton made everything work as I expected.