我希望将组合框的TextElement.Foreground属性链接到对象:"tValeur"的变量:"ALV_COULEUR"。
我在输出中注意到,它没有找到变量ALV_COULEUR .
System.Windows.Data错误: 40 : BindingExpression路径错误:'ALV_COULEUR‘属性没有在'object’Attribut‘(HashCode=35307513)’上找到。BindingExpression:Path=ALV_COULEUR;DataItem='Attribut‘(HashCode=35307513);目标元素为'ComboBox’(名称=‘’);目标属性为‘前台’(键入'Brush')
链接的对象是值,而不是“Attribut”.
在这种情况下不可能有约束力吗?
谢谢!
<ComboBox IsEditable="True"
TextElement.Foreground="{Binding ALV_COULEUR, Converter={StaticResource IntToBrushConverter}, Mode=OneWay}"
ItemsSource="{Binding tValeur, Mode=OneWay}" SelectedValuePath="ALV_ID" DisplayMemberPath="ALV_VALEUR"
SelectedValue="{Binding ATT_VALEUR, Converter={StaticResource StringToIntConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding IsEnabled, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
</ComboBox>编辑:
我的课:
public class Attribut
{
public int ATT_ID { get; set; }
public string ATT_LIBELLE { get; set; }
public List<ValeurAttribut> tValeur { get; set; }
}
public class ValeurAttribut
{
public int ALV_ID { get; set; }
public string ALV_VALEUR { get; set; }
public int ALV_COULEUR { get; set; }
}DataContext :链接到ObservableCollection<Attribut>()的DataGrid
发布于 2018-08-13 14:54:26
使用ItemTemplate定义TextBlock,并将其Foreground属性绑定到ALV_COULEUR源属性。还将TextBlock.Foreground绑定到ComboBox的SelectedItem属性
<ComboBox IsEditable="True"
TextBlock.Foreground="{Binding SelectedItem.ALV_COULEUR, Converter={StaticResource IntToBrushConverter}, RelativeSource={RelativeSource Self}}">
ItemsSource="{Binding tValeur, Mode=OneWay}" SelectedValuePath="ALV_ID" DisplayMemberPath="ALV_VALEUR"
SelectedValue="{Binding ATT_VALEUR, Converter={StaticResource StringToIntConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding IsEnabled, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ALV_VALEUR}" Foreground="{Binding ALV_COULEUR, Converter={StaticResource IntToBrushConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>https://stackoverflow.com/questions/51824890
复制相似问题