-
Notifications
You must be signed in to change notification settings - Fork 771
Open
Labels
Description
Describe the bug
TemplateBinding to an ICommand property doesn't work in WinUI. However, explicitly binding using the RelativeSource does.
BgLabelControlApp.zip
This doesn't work:
<ResourceDictionary xmlns:local="using:ClassLibrary1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Style TargetType="local:BgLabelControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:BgLabelControl">
<Grid Background="{TemplateBinding Background}"
Height="100"
Width="100">
<Button Content="{TemplateBinding Label}"
HorizontalAlignment="Center"
Command="{TemplateBinding GoBack}"
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
This works:
<ResourceDictionary xmlns:local="using:ClassLibrary1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Style TargetType="local:BgLabelControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:BgLabelControl">
<Grid Background="{TemplateBinding Background}"
Height="100"
Width="100">
<Button Content="{TemplateBinding Label}"
HorizontalAlignment="Center"
Command="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=GoBack, Mode=OneWay}"
VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Steps to reproduce the bug
- Expand the attached zip file.
- Run the application. The second button doesn't work
- Replace the TemplateBinding with "{Binding RelativeSource={RelativeSource TemplatedParent}, Path=GoBack, Mode=OneWay}"
- Run the application. The second button works.
Expected behavior
One expects TemplateBinding to bind to the templated parent.
Screenshots
No response
NuGet package version
No response
Windows app type
- UWP
- Win32
Device form factor
Desktop
Windows version
Windows 11 (21H2): Build 22000
Additional context
No response
Panda-Sharp, Leisvan and Soap-141