-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ElementName bindings don't work inside ItemsRepeater DataTemplate #560
Comments
Is there any follow up on this? Almost 2 years later and it seems like a pretty big thing to be missing, especially if we want ItemsRepeater to replace ListView/GridView, where it works fine. |
I'm also running into the same issue. Are there any work arounds for the issue? |
@jevansaks I can confirm this bug is still present. I've tried both |
I'm sorry to hear that. @RealTommyKlein @ranjeshj any ideas? |
I'm also running into the same issue even with the latest versions. |
This is a pain see folks hit trying to implement MVVM patterns. This effects both WinUI 2 and WinUI 3. Someone recently created a nice isolated repro of the ItemsControl/ItemsRepeater difference here on one of our bugs, thanks to @leoshusar: <ItemsControl ItemsSource="{x:Bind ViewModel.Items}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="x:String">
<ComboBox Name="cmbTest1">
<ComboBoxItem Content="TextBlock" Tag="TextBlock" />
<ComboBoxItem Content="HyperLink" Tag="HyperLink" />
<i:Interaction.Behaviors>
<ic:EventTriggerBehavior EventName="SelectionChanged">
<ic:EventTriggerBehavior.Actions>
<ic:InvokeCommandAction Command="{Binding ElementName=PageRoot, Path=ViewModel.Test1Command}" CommandParameter="{Binding ElementName=cmbTest1}" />
</ic:EventTriggerBehavior.Actions>
</ic:EventTriggerBehavior>
</i:Interaction.Behaviors>
</ComboBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ItemsRepeater Grid.Column="1" ItemsSource="{x:Bind ViewModel.Items}">
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="x:String">
<ComboBox Name="cmbTest2">
<ComboBoxItem Content="TextBlock" Tag="TextBlock" />
<ComboBoxItem Content="HyperLink" Tag="HyperLink" />
<i:Interaction.Behaviors>
<ic:EventTriggerBehavior EventName="SelectionChanged">
<ic:EventTriggerBehavior.Actions>
<ic:InvokeCommandAction Command="{Binding ElementName=PageRoot, Path=ViewModel.Test2Command}" CommandParameter="{Binding ElementName=cmbTest2}" />
</ic:EventTriggerBehavior.Actions>
</ic:EventTriggerBehavior>
</i:Interaction.Behaviors>
</ComboBox>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater> Recording.2023-06-19.011441.mp4FYI @bpulliam |
Here's a sample app project with a workaround that works for me. If you want to see it in action, here's a video. |
Any ETA for this issue? |
Not sure what ItemsControl is doing to make this work. Here is a simpler repro
There is a small typo in the repro steps above - cmbTest2 does not exist. |
I would presume it is a XAML namescope issue as ElementName requires the element to be in the same namescope, but as we can't debug the namescoping externally someone MS related will have to track it down. But given how "non-traditional" ItemsRepeater layouts are handled compared to normal Xaml ItemsControls I would imagine there's an obvious break point. It could be that elements are namescoped to the RecyclePool for example. |
@bpulliam any news? i can not use new control ItemsView because of this bug. |
I wouldn't call adding x:Bind/Binding is just broken in so many of these scope scenarios which adds so much friction in developing with XAML (see #2508). If a bit of focus could be spent in this space, it could make the platform a dream to work with. |
@duncanmacmichael any new for this? |
@michael-hawker |
I'm honestly not sure since engineering handles bugs directly and I'm a PM, but it looks like @ranjeshj is working on this so we can ask him for an update. :) |
@RealTommyKlein helped narrow this down to this code -
|
@ranjeshj any update? |
@llongley fixed in v1.5 or v1.4.5? |
@ghost1372 This is fixed in the upcoming release of v1.5. |
This doesn't appear to be fixed? (1.5.240404000), anyone else here still encountering the issue? |
The simple repro I had works on latest 1.5 release. #560 (comment). @DominicMaas is your repro different? can you file a new issue with your repro (preferably small/standalone) |
Please test with this repro |
Still Facing this Issue on Windows App SDK v1.5.240404000 |
Same here still facing the issue. |
I run my repro project with all v1.5.x available versions but none of them worked. |
The same thing happens to ItemsView, I believe. |
Same issue still there when you use the ItemsRepeater inside a ControlTemplate in a style. Binding with a relative source to the templatedparent does not work. |
Describe the bug
As described, using ElementName bindings inside the datatemplate of an Items Repeater appears to fail. The same template inside anything that inherits ItemsControl works fine.
Steps to reproduce the bug
Steps to reproduce the behavior:
Expected behavior
It works.
Version Info
O.S. 18362.53
MinVersion SDK: 17134
MaxVersion SDK: 17763
NuGet package version:
2.1.190405004
The text was updated successfully, but these errors were encountered: