x:Load="{x:Bind Blah, Mode=OneWay}"
Describe the bugx:Bind
works in control template since 1809. There is a bug however which prevents x:Load
from being used with x:Bind
. Note that x:Load="False"
work, only x:Load={x:Bind Blah, Mode=OneWay}
doesn't.
CustomControlTemplate.xaml
and
CustomControlTemplate.cs
(using user control template -> rename is probably the fastest)
// xaml
<ResourceDictionary
x:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XLoadBindingNotWorkingInTemplate"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Style TargetType="local:CustomControl" BasedOn="{StaticResource DefaultCustomControlStyke}"/>
<Style x:Key="DefaultCustomControlStyke" TargetType="local:CustomControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CustomControl">
<TextBlock x:Name="textBlock" Text="{x:Bind Greeting, Mode=OneWay}" x:Load="{x:Bind IsVisible, Mode=OneWay}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
// cs
public sealed partial class CustomControlTemplate : ResourceDictionary
{
public CustomControlTemplate()
{
this.InitializeComponent();
}
}
CustomControl
that use the style
public sealed class CustomControl : Control, INotifyPropertyChanged
{
public CustomControl()
{
this.DefaultStyleKey = typeof(CustomControl);
}
public event PropertyChangedEventHandler PropertyChanged;
public bool IsVisible { get; private set; }
public string Greeting { get { return "Hello world"; } }
public void MakeVisible()
{
IsVisible = true;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsVisible)));
}
}
obj
and find
CustomControlTemplate.g.cs
, notice 2 compiler errors where
obj2
is used without being declared
x:Load="{x:Bind Blah, Mode=OneWay}"
works.
No response
Windows app type UWP Win32 Device form factor没有 React
Windows version没有 React
Additional contextdataRoot.GetTemplateChild
instead of
obj2.FindName
. Minimal repro: https://github.com/roxk/XLoadBindingNotWorkingInTemplateCs