title: Xamarin XAML to C# Data Trigger
body: <p>In reference to this question below I have XAML working, but am struggling with converting to C#</p>
  <p><a href="https://stackoverflow.com/questions/72404330/xamarin-maui-xaml-to-c-sharp">Xamarin / MAUI XAML to C#</a></p>
  <p>Here is my attempt that isn't working and I'm not sure why... My goal is when <code>LayoutState.Success</code> it updated via <code>VenuePageViewModel</code>, <code>VenueSuccessContentView</code> should display inside the <code>cvWrap</code> <code>ContentView</code> on the Page.</p>
  <pre><code>public partial class VenuePageViewModel : ObservableObject
  {
      [ObservableProperty]
      private LayoutState layoutState = LayoutState.Loading;
  
      public VenuePageViewModel()
      {
          LayoutState = LayoutState.Success;
      }
  }
  
  public class VenueSuccessContentView : ContentView
  {
      public VenueSuccessContentView()
      {
          Content = new Label() { Text = &quot;hello world&quot;, TextColor = Colors.Red };
      }
  }
  
  public class MainPageCS : ContentPage
  {
      public MainPageCS()
      {
          BindingContext = new VenuePageViewModel();
  
          var venueSuccessCV = new VenueSuccessContentView();
          Resources.Add(nameof(LayoutState.Success), venueSuccessCV);
  
          var cvWrap = new ContentView();
          var cv = new ContentView();
          cvWrap.Content = cv;
  
          Content = cvWrap;
  
          var datatrigger = new DataTrigger(typeof(ContentView))
          {
              Binding = new Binding(source: RelativeBindingSource.TemplatedParent, path: nameof(VenuePageViewModel.LayoutState)),
              Value = LayoutState.Success,
              Setters = {
                  new Setter { Property =  ContentView.ContentProperty, Value = venueSuccessCV },
              }
          };
  
          cvWrap.Triggers.Add(datatrigger);
      }
  }
  </code></pre>
  <p><strong>Minimal Repo: <a href="https://github.com/aherrick/DataTriggerCSharpMaui" rel="nofollow noreferrer">https://github.com/aherrick/DataTriggerCSharpMaui</a></strong></p>