DataTrigger in ControlTemplate not setting Image source

前端 未结 2 1957
悲哀的现实
悲哀的现实 2021-01-28 10:34

I have a ControlTemplate that i defined for showing a View model in my required format. However, I am not able to set the Image\'s source property from the DataTrigger of the Co

相关标签:
2条回答
  • 2021-01-28 10:51

    fine , wierd contorl design ...

        <DataTrigger Binding="{Binding Path=DataContext.IsConnected, 
             RelativeSource={RelativeSource AncestorType=ItemsControl}}" Value="True">
                <Setter Property="Source"
                        TargetName="imgConnectedStatus"
                        Value="/Resources/GreenDot.png"/>
         </DataTrigger>
    

    since you are using a DataTrigger from an item's precpective , the DataTemplates DataContext is an object from your ItemsSource , RelativeSource to the containing control , Path to it's DataContext.Property

    0 讨论(0)
  • 2021-01-28 11:02

    By looking at the following link http://social.msdn.microsoft.com/Forums/vstudio/en-US/a3bf91a8-e618-41c6-a1ad-be9e19581fd6/datatrigger-inside-controltemplate-issue

    It became clear that i should not use TemplatedParent. Setting the {RelativeSource Self} in the binding solved the problem.

            <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding AdditionalContent.IsComponentShutdown, RelativeSource={RelativeSource Self}}"
                             Value="False">
                    <Setter TargetName="imgStatus"
                            Property="Source"
                            Value="/Resources/GreenDot.png"/>
                </DataTrigger>
            </ControlTemplate.Triggers>
    
    0 讨论(0)
提交回复
热议问题