问题标签 [templatebinding]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - ListViewItem 与 CheckBox IsChecked 绑定到 ViewModel
我有一个带有 DataTemplate 的 ListView,用于为每个 ListViewItem 显示一个复选框。
ItemsSource ("TableNames") 在 ViewModel 中是这样定义的:
如何将 IsChecked 从 Checkbox 绑定到 Item.IsSelected 属性?
我的代码不起作用。
c# - WPF TemplateBinding 到模板化父对象的 DataContext
我们在四个 XAML 视图中有四个相同的带有网格的弹出窗口。我想将该 XAML 移动到模板并通过 Style 应用于所有四个中的 ContentControls。问题在于传递网格中项目的来源。我们从四个不同的视图模型中得到了它。每种情况都不同,唯一不同的是四种情况。我可能最终会一致地重命名它们,但我想这是一个单独的问题。
显然我根本不了解 TemplateBinding。如何将模板的子属性绑定到要应用模板的 ContentControl 的属性?
除了 DataSource 属性的值发生变化外,网格的 XAML 与我们直接使用它时运行良好的 XAML 相同。
我添加了 TextBlock 只是为了看看我是否可以绑定任何东西。我确实到达NaN
那里。
wpf - 自定义控件中的 WPF 自定义 IList DependencyProperty 行为异常
我想创建一个显示其他控件(按钮)列表的自定义控件。我有一个名为 Buttons 的 DependencyProperty
并将其绑定在模板中,如下所示:
当像这样在 XAML 中使用控件的多个实例时
所有“按钮”都将分配给控件的最后一个实例,如下图所示:
我以类似的方式添加了一个自定义的“页脚”属性,该属性按预期工作。我不知道我做错了什么,所以任何帮助将不胜感激。我感觉它与默认值“New List(Of Control)”有关。
示例项目可在此处找到:CustomControl 示例
非常感谢!
c# - 通过 Templatebinding 改变 Contentpresenter 的 ContentTemplate
是否有可能做这样的事情(见下面的代码)?我尝试了不同的方法,但都没有奏效。它是对 TemplateBinding 的限制吗?我不想通过 Staticressources 设置 ContentTemplates(这可行),因为控件应该在运行时更改模板。我怎样才能做到这一点?
wpf - Binding to AlternationCount of ItemsControl from ItemTemplate of a nested ItemsControl
I have an ItemsControl nested in the DataTemplate of another ItemsControl. This seemed like the easiest way to display a grid of numbers from a two-dimensional array, which it did very nicely. The problem I have is that I want to change the color a particular number in the grid. I was hoping to trigger off the AlternationIndex of both ItemsControls, so I can identify exactly which number to highlight.
In the DataContext for the parent ItemsControl I have a 2-D array of integers like this:
_grid is initialized to a 20x20 array of numbers.
Here is my XAML for the ItemsControls:
I can easily get an entire column of the numbers to be colored red if I leave the second condition off the MultiDataTrigger, but I can't get the second condition to work. Any thoughts on how I can do this? I can probably do it with a DataGrid or something, but now I'm really interested in how to do this binding...if it is even possible.
UPDATE:
@d.moncada gave me the hint I needed to figure out what I had done wrong. Instead of looking for an ancestor of type ItemsControl, I needed to look for ContentPresenter.
c# - WPF 按钮样式和模板
所以我有按钮及其样式:
它工作正常,我有以下结果(海蓝宝石背景不是 Button 的一部分,它属于 Window):
但后来我想替换按钮的内容并改变我的风格:
现在我的按钮变得很糟糕:
正如你所看到的,我的按钮失去了它的边框和背景,当鼠标悬停在它上面时它不会改变它的视图。我在哪里错了,我应该怎么做才能防止它?
UPD
当我做这样的事情时:
然后我得到这个结果:
如您所见,这类似于第一个结果,其中缺少复选标记
firebase - 在模板重复中使用 firebase-element 时显示错误
数据看起来像这样
并在另一个位置存储实际用户数据。
在这里,我期望模板重复相应地呈现每个用户(member1、member2、member3)。但是,它为 3 个条目打印出相同的名称,就好像它为模板重复中的所有 3 个 firebase 元素重新使用变量“member”一样,这实际上没有意义。
我试图修改 objKeys 函数以返回
然后将内部成员对象用于 firebase 元素,但结果仍然相同
我不理解模板重复正确并在这里错误地使用它吗?还是聚合物模板的错误。
c# - 在 ASPX 中定义自定义对象时出现 NullReferenceException
我正在尝试创建一个自定义上下文菜单作为用户控件。此用户控件的代码如下所示:
然后,我在与用户控件相同的命名空间ContextMenuItem
中定义了类型(实际上在同一个文件中),它本质上是一个菜单项:
用户控件的ascx
页面包含一个repeater
定义如下的控件:
最后在注册后在页面中使用它,我有:
现在,当我运行它时,我NullReference
在线收到一个解析错误
不运行时,Visual Studio 还说Element 'ContextMenuItem' is not a known element.
它在运行时也没有捕获异常,所以也许这样我可以查看堆栈跟踪以了解发生了什么。我只是想知道是否有人遇到过类似的问题。任何帮助表示赞赏。
c# - 绑定路径中的模板绑定
我有一个Custom Control
with 依赖属性Header
。该Generic.xaml
控件有一种样式。我想设置模板某些部分的可见性,以便它依赖于Header
控件的属性。
此行引发异常:
根据异常消息,Binding 的 Path 属性内不能有 Binding(我已经知道了)xD
没有双重绑定怎么能做到这一点?如何在不使用 TemplateBinding 的情况下访问自定义控件的属性?
wpf - 模板绑定错误
我开发了一个具有依赖属性的自定义控件
当我尝试从外部 xaml 设置控件的 ControlTemplate 时出现问题
听起来像上面带有 TemplateBinding 的字符串中的“XamlParseException:字典中不存在给定的键”。有什么问题?