【发布时间】:2012-11-20 15:33:58
【问题描述】:
我有以下代码:
<ControlTemplate x:Key="ViewItemTemplate"
TargetType="ListViewItem">
<StackPanel Orientation="Horizontal">
<CheckBox Margin="0,0,3,0" x:Name="CkBox">
<CkBox.IsChecked>
<Binding Path="IsSelected"
Mode="TwoWay">
<Binding.RelativeSource>
<RelativeSource Mode="TemplatedParent" />
</Binding.RelativeSource>
</Binding>
</CkBox.IsChecked>
<DataTrigger Binding="{Binding InvalidForeground}" Value="true">
<Setter TargetName="CkBoxVisual" Property="Foreground" Value="#999999"/>
</DataTrigger>
</CheckBox>
<ContentPresenter />
</StackPanel>
</ControlTemplate>
如何绑定 InvalidForeground?我在网上查看了许多他们告诉使用 DataTemplate 的示例。但是当我在 StackPanel 上方添加 DataTemplate 时出现错误?我是不是做错了什么?
我正在尝试绑定 InvalidForeground,以便我可以添加一些代码。我收到一个错误:由于未知的 DataContext,无法解析符号“InvalidForeground”。
【问题讨论】:
-
你想达到什么目的?
-
你能说得更具体点吗?你在问什么?你遇到了什么错误?
-
@DanielHilgarth - 我正在尝试绑定 InvalidForeground,以便我可以添加一些代码。我收到一个错误:由于未知的 DataContext,无法解析符号“InvalidForeground”。
-
您正在尝试绑定
InvalidForeground。但它是什么?它在哪里定义?你说的“所以我可以添加一些代码”是什么意思?? -
@DanielHilgarth - InvalidForeground 只是一个布尔值,它取真或假。我想在代码中添加属性以获取该值并更改设计中复选框文本的 ForegroundColor。