How do I use WPF bindings with RelativeSource?

前端 未结 13 2302
执念已碎
执念已碎 2020-11-22 03:00

How do I use RelativeSource with WPF bindings and what are the different use-cases?

13条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 03:34

    I didn't read every answer, but I just want to add this information in case of relative source command binding of a button.

    When you use a relative source with Mode=FindAncestor, the binding must be like:

    Command="{Binding Path=DataContext.CommandProperty, RelativeSource={...}}"
    

    If you don't add DataContext in your path, at execution time it can't retrieve the property.

提交回复
热议问题