Skip to content
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

TemplateBinding throws an exception when used in a Selector in the ControlTheme #14576

Closed
workgroupengineering opened this issue Feb 10, 2024 · 4 comments · Fixed by #14612
Closed
Assignees

Comments

@workgroupengineering
Copy link
Contributor

Describe the bug

XamlX throws Unable to cast object of type 'XamlX.Ast.SkipXamlValueWithManipulationNode' to type 'XamlX.Ast.IXamlAstPropertyReference'.

Stack

10:31:07.792 [Error] 9076 UpdateXamlResult error
System.Xaml.XamlException: Unable to cast object of type 'XamlX.Ast.SkipXamlValueWithManipulationNode' to type 'XamlX.Ast.IXamlAstPropertyReference'.
10:31:31.176 [Information] 9076 Stopping previewer process
10:31:31.177 [Information]  Process exited
10:31:31.177 [Information]  Stopping previewer process
10:32:25.478 [Information]  Started AvaloniaDesigner.CreateCompletionMetadataAsync() for "C:\GitHub\Avalonia\samples\Sandbox\obj\Debug\net6.0\Avalonia\references"
10:32:25.479 [Information]  Starting previewer process for '"C:\GitHub\Avalonia\samples\Sandbox\bin\Debug\net6.0\Sandbox.dll"'
10:32:25.483 [Information] 24432 Started previewer process for '"C:\GitHub\Avalonia\samples\Sandbox\bin\Debug\net6.0\Sandbox.dll"'. Waiting for connection to be initialized.
10:32:25.926 [Information] 24432 Connection initialized
10:32:27.424 [Error] 24432 UpdateXamlResult error
System.Xaml.XamlException: Unable to cast object of type 'XamlX.Ast.SkipXamlValueWithManipulationNode' to type 'XamlX.Ast.IXamlAstPropertyReference'.

To Reproduce

Steps to reproduce the behavior:

Add folowing xaml

  <ControlTheme x:Key="{x:Type NumericUpDown}"
                TargetType="NumericUpDown">
        ....
        <Style Selector="^[ButtonSpinnerLocation=Left] /template/ TextBox#PART_TextBox">
          <Setter Property="InnerRightContent" Value="{TemplateBinding InnerContent}"/>
        </Style>

        <Style Selector="^[ButtonSpinnerLocation=Right] /template/ TextBox#PART_TextBox">
          <Setter Property="InnerLeftContent" Value="{TemplateBinding InnerContent}"/>
        </Style>
  </ControlTheme>

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment

  • OS: Any
  • Avalonia-Version: ffff19e

Additional context

if change like this works:

  <ControlTheme x:Key="{x:Type NumericUpDown}"
                TargetType="NumericUpDown">
        ....
    <Style Selector="^[ButtonSpinnerLocation=Left] /template/ TextBox#PART_TextBox">
      <Setter Property="InnerRightContent" Value="{Binding InnerContent, RelativeSource={RelativeSource TemplatedParent}}"/>
    </Style>

    <Style Selector="^[ButtonSpinnerLocation=Right] /template/ TextBox#PART_TextBox">
      <Setter Property="InnerLeftContent" Value="{Binding InnerContent, RelativeSource={RelativeSource TemplatedParent}}"/>
    </Style>
  </ControlTheme>
@timunie
Copy link
Contributor

timunie commented Feb 12, 2024

TemplateBinding is more limited than Binding for performance reasons. I believe this is by design and if it's not enough, you need to fall back to a normal Binding (like you did already). Note, you are outside ControlTemplate here. I agree that the error message could be improved.

@maxkatz6 maxkatz6 self-assigned this Feb 12, 2024
@maxkatz6
Copy link
Member

There should be another warning or an error before this one.

@maxkatz6
Copy link
Member

I also can't reproduce this issue by adding InnerContent property and these setters.

@workgroupengineering
Copy link
Contributor Author

TemplateBinding is more limited than Binding for performance reasons. I believe this is by design and if it's not enough, you need to fall back to a normal Binding (like you did already). Note, you are outside ControlTemplate here. I agree that the error message could be improved.

Then this shouldn't have worked either {Binding InnerContent, RelativeSource={RelativeSource TemplatedParent}} but only

{Binding InnerContent, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type NumericUpDown}}}

I also can't reproduce this issue by adding InnerContent property and these setters.

I attach a modified SandBox that simulates the problem

Sandbox.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants