Binding to custom control inside DataTemplate for ItemsControl

前端 未结 1 567
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 08:49

I have a problem with bindings for DataTemplate based on defined DataType in ItemsControl, when I want to bind to my custom us

相关标签:
1条回答
  • 2020-11-27 08:57

    The problem is that you explicitly set the DataContext of your UserControl to itself:

    DataContext="{Binding Mode=OneWay, RelativeSource={RelativeSource Self}}
    

    Remove that assignment and write the ItemName binding like this:

    <TextBlock Text="{Binding ItemName,
        RelativeSource={RelativeSource AncestorType=UserControl}}"/>
    

    or like this

    <TextBlock Text="{Binding ItemName, ElementName=ItemRowControl}"/>
    
    0 讨论(0)
提交回复
热议问题