microsoft / microsoft/microsoft-ui-xaml

[xBind] unexpected generated code when using a control name inside a function binding inside datatemplate

Open
#10,161 0 comments 1 reaction 0 assignees View on GitHub
area-XamlCompiler bug team-Markup
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

using an element property as an argument for function binding inside template binding (testTextBox.Text in the following example)
```








```
the generated g.cs file has an unexpected generated code
```

private bool TryGet_testTextBox(out global::Microsoft.UI.Xaml.Controls.TextBox val)
{
global::System.String obj;
if (TryGet_(out obj) && obj != null)
{
val = bindings.obj4;
return true;
}
else
{
val = default(global::Microsoft.UI.Xaml.Controls.TextBox);
return false;
}
}

private bool TryGet_(out global::System.String val)
{
val = this;
return true;
}

```
.
correcting the generated code for `TryGet_testTextBox`

`val = bindings.obj4; ` to `val = obj4;`

and `TryGet_`

` val = this;` to ` val = this.dataRoot;`

is the expected code. which works fine after testing

### Steps to reproduce the bug

use an element name in function binding inside a datatemplate

### Expected behavior

_No response_

### Screenshots

_No response_

### NuGet package version

WinUI 3 - Windows App SDK 1.6.2: 1.6.241106002

### Windows version

_No response_

### Additional context

the only work around i found is to avoid the function binding

for the mentioned example above,

```





```

```

public class Decoy : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

private string _value;
public string Value
{
get => _value;
set
{
if (_value != value)
{
_value = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Value)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Result)));
}
}
}

public string Result => Value;
}
```

[min repro project link](https://github.com/mouhamedhazem149/xBindControlInResTemplateRepro)

Contributor guide

Open the contributing guide

Research direction

Start with xBind function binding inside a DataTemplate and inspect the generated g.cs output described in the issue. Compare TryGet_testTextBox and TryGet_ with the expected dataRoot and object references, then validate the result using the linked minimal repro project. Done means the generated code handles the named control correctly without the workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
frontend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.