Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

TemplateBinding issues on binding different properties

Open ahopper opened this issue 5 years ago • 1 comments

The following attempt to bind TextBox.Text to Slider.Value does not work, there are no errors but nothing is displayed.

<Style Selector="Slider:horizontal">
      <Setter Property="MinWidth" Value="40"/>
      <Setter Property="MinHeight" Value="20"/>
      <Setter Property="Template">
        <ControlTemplate>
          <Panel>
            <TextBlock Name="PART_Label" Margin ="0,5,0,0" HorizontalAlignment="Left"  />
            <TextBlock Name="PART_ValueTip" Margin ="0,5,0,0" HorizontalAlignment="Center" Text="{TemplateBinding Value}"  />
            <Border Name="TrackBackground" Height="4" Margin="6,0" VerticalAlignment="Center"/>
            <Track Name="PART_Track" Orientation="Horizontal">
              <Track.DecreaseButton>
                <RepeatButton Name="PART_DecreaseButton"
                              Classes="repeattrack" />
              </Track.DecreaseButton>
              <Track.IncreaseButton>
                <RepeatButton Name="PART_IncreaseButton"
                              Classes="repeattrack" />
              </Track.IncreaseButton>
              <Thumb MinWidth="20" MinHeight="20">
                <Thumb.Template>
                  <ControlTemplate>
                    <Panel Background="Transparent">
                      <Ellipse Width="12" Height="12" Fill="{DynamicResource ThemeAccentBrush}" />
                    </Panel>
                  </ControlTemplate>
                </Thumb.Template>
              </Thumb>
            </Track>
          </Panel>
        </ControlTemplate>
      </Setter>
    </Style>

Trying to do the same thing with a setter fails with "Could not find property TextBlock.Value"

<Style Selector="Slider /template/ TextBlock#PART_ValueTip">
      <Setter Property="Text" Value="{TemplateBinding Value, Mode=OneWay}"/>
    </Style>

Using Text="{Binding $parent[Slider].Value}" works.

ahopper avatar Mar 09 '19 14:03 ahopper

This still behaves as described above. Maybe it is intended behaviour of TemplateBinding ?

ahopper avatar Jan 02 '22 12:01 ahopper