In winui 3, how to bind to a dependency property of my UserControl, inside a DataTemplate of a contained ItemsControl?

Voyageur Solitaire 1 Reputation point
2024-09-02T00:52:25.9866667+00:00

So I have a UserControl, which contains an ItemsControl. I need the controls defined inside the DataTemplate to bind to a dependency property in my UserControl.

Let's say my UserControl has a dependency property MyProp. I want to do the following in my xaml code...

<UserControl>
  ...
   <ItemsControl>
      <ItemsControl.ItemTemplate>
        <DataTemplate x:DataType="MyType">
           <custom:ControlThatExpectsMyType
              SomeProperty={x:Bind MyProp}>
           </custom:ControlThatExpectsMyType>
        </DataTemplate>
      <ItemsControl.ItemTemplate>
   </ItemsControl>
  ...
</UserControl>

The MyProp dependency property in the above snippet is not part of MyType, but of my UserControl. Both Binding and x:Bind are acceptable solutions, but none of the "old wpf ways" seem to be working in winui 3.

So, what's the proper -expected- way to do it in winui 3?

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
780 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.