Skip to content

Xaml binding expression markup validation is not strong enough #57

Closed

Description

@Henk7

I know two styles to write a TemplateBinding with an attached DepdendencyProperty.

<CSControls:TextButton CSControls:Element.Text="firsttest">
     <CSControls:TextButton.Template>
          <ControlTemplate TargetType="Control">
              <Border Background="Gray">
                 <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=(CSControls:Element.Text)}" 
                            />
               </Border>
          </ControlTemplate>
    </CSControls:TextButton.Template>
</CSControls:TextButton>

AND

<CSControls:TextButton CSControls:Element.Text="secondtest">
         <CSControls:TextButton.Template>
             <ControlTemplate TargetType="Control">
                 <Border Background="Green">
                     <TextBlock Text="{TemplateBinding CSControls:Element.Text}" />
                 </Border>
             </ControlTemplate>
         </CSControls:TextButton.Template>
     </CSControls:TextButton>

The first variant with the gray background works on android, the second one doesn't.
Which means that the text "firsttest" is visible the text "secondtest" is not.
Both variants are working on UWP head.
PS: Haven't tried WASM/iOS

UPDATE: I found out that only the missing bracket is the reasion

<TextBlock Text="{TemplateBinding (CSControls:Element.Text)}"/>
works and
<TextBlock Text="{TemplateBinding CSControls:Element.Text}"/>
doesn't

Activity

  1. jeromelaban commented on Jun 22, 2018

    @jeromelaban
    Member

    @Henk7 Looks like Bindings need more markup validation, I'll adjust the issue title accordingly.

    Thanks !

  2. changed the title [-]Attached DependencyProperty in a TemplateBinding doesn't work on android[/-] [+]Xaml binding expression markup validation is not strong enough[/+] on Jun 22, 2018
  3. added
    kind/bug
    on Jun 22, 2018
  4. added
    project/binding 🪢
    on Sep 15, 2020
  5. added
    project/animations 🎡
    and removed
    project/animations 🎡
    on Sep 21, 2020
  6. added
    difficulty/tbd
    on Feb 15, 2021
  7. added
    difficulty/medium 🤔
    and removed
    difficulty/tbd
    on May 31, 2021
  8. Youssef1313 commented on Aug 6, 2021

    @Youssef1313
    Member

    I've tried to reproduce this as follows:

    <Page
        x:Class="App8.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App8"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:mynamespace="using:Windows.UI.Xaml.Controls"
        xmlns:shared="using:TestNamespace"
        mc:Ignorable="d">
    
        <StackPanel>
            <mynamespace:Button Height="200" Width="200">
                <mynamespace:Button.Template>
                    <ControlTemplate TargetType="mynamespace:Button">
                        <Ellipse Height="{TemplateBinding mynamespace:Button.Height}"
                                 Width="{TemplateBinding mynamespace:Button.Width}"
                                 Fill="LightBlue" />
                    </ControlTemplate>
                </mynamespace:Button.Template>
            </mynamespace:Button>
        </StackPanel>
    </Page>
    

    But it works without the parenthesis. Anything I'm missing?

    cc @jeromelaban @MartinZikmund

  9. jeromelaban commented on Aug 6, 2021

    @jeromelaban
    Member

    There were some improvements with this issue, the parser now reports more detailed errors.

  10. MartinZikmund commented on Sep 29, 2021

    @MartinZikmund
    Member

    @Henk7 can we close this one now?

  11. Henk7 commented on Sep 29, 2021

    @Henk7
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty/medium 🤔kind/bugproject/binding 🪢

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions