gpt4 book ai didi

.net - DataTemplate 中的 TemplateBinding 不起作用

转载 作者:行者123 更新时间:2023-12-01 06:03:17 26 4
gpt4 key购买 nike

我正在创建 模板化控件 在我的通用 Windows 应用程序中。

问题是在 <Button Content="{Binding}" Command="{TemplateBinding AddCharCommand}" /> TemplateBinding不起作用。

似乎问题在于它是在 DataTemplate 中定义的。 .

这是Style并将模板应用于我的控件。

<Style TargetType="local:CoordinatesControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CoordinatesControl">

<ListView ItemsSource="{TemplateBinding Numbers}">
<ListView.ItemTemplate>
<DataTemplate>
<Button Content="{Binding}"
Command="{TemplateBinding AddCharCommand}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

最佳答案

您不能使用 TemplateBinding里面 DataTemplate ,但有解决方法:

  • 您可以使用 DataContext 创建某种隐藏元素的代理。你需要。更多详情 here .
  • 您可以创建一种 RelativeSource绑定(bind)查找Ancestor喜欢 WPF .更多详情 here
  • 关于.net - DataTemplate 中的 TemplateBinding 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42651984/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com