WPF background property does not point to a dependencyobject in path' (0). (1 )'

Source: Internet
Author: User

When you use <ListBox. itemtemplate> to create a tabitem template, you want to use an animation to add a flickering effect to the tabitem. The Code is as follows:

<Border BorderBrush="#FFAAAAAA" BorderThickness="0,0,0,1" Background="White"><Border.Style><Style TargetType="Border"><Style.Triggers><DataTrigger Binding="{Binding Path=Quoted}" Value="true"><DataTrigger.EnterActions><BeginStoryboard Name="OperationStatusStoryboard"><Storyboard FillBehavior="Stop"><ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" From="White" To="Pink" Duration ="0:0:0.125" AutoReverse="True" RepeatBehavior="Forever" /></Storyboard></BeginStoryboard></DataTrigger.EnterActions></DataTrigger><DataTrigger Binding="{Binding Path=Quoted}" Value="false"><DataTrigger.EnterActions><RemoveStoryboard BeginStoryboardName="OperationStatusStoryboard"></RemoveStoryboard></DataTrigger.EnterActions></DataTrigger></Style.Triggers></Style></Border.Style>

When ListBox is flushed for the first time, background property does not point to a dependencyobject in path '(0). (1)' is reported )'

However, the targettype of the style is clearly border, and there is no reason to find the background attribute. The animation effect is fine after the first brush. That is to say, before ListBox show (), coloranimation could not find border. That is to say, it may just find the style object along the logic tree and try to bind the background to the style object. We know that style directly inherits from dispatcherobject. It is not a dependencyobject, not a visual subclass. The problem is when coloranimation can find the border object. When can the attribute value set by style be applied to border? From the perspective of UI behavior, it is obvious that the attribute value can be applied only after the border. Loaded () event is completed. Of course, this need to be verified.

Because my XAML does not have the CS code, we apply mvvmlight and hope to hand over the interface code to the artist. Therefore, solving this problem from the loaded () Event violates the mvvmlight principle and finds a solution from Stack over flow:

<Border BorderBrush="#FFAAAAAA" BorderThickness="0,0,0,1">                                <Border.Style>                                    <Style TargetType="Border">                                        <Setter Property="Background">                                            <Setter.Value>                                                <SolidColorBrush Color="White"/>                                            </Setter.Value>                                        </Setter>                                        <Style.Triggers>                                            <DataTrigger Binding="{Binding Path=Quoted}" Value="true">                                                <DataTrigger.EnterActions>                                                    <BeginStoryboard Name="OperationStatusStoryboard">                                                        <Storyboard FillBehavior="Stop">                                                            <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" From="White" To="Pink" Duration ="0:0:0.125"                                                                         AutoReverse="True" RepeatBehavior="Forever" />                                                        </Storyboard>                                                    </BeginStoryboard>                                                </DataTrigger.EnterActions>                                            </DataTrigger>                                            <DataTrigger Binding="{Binding Path=Quoted}" Value="false">                                                <DataTrigger.EnterActions>                                                    <RemoveStoryboard BeginStoryboardName="OperationStatusStoryboard"></RemoveStoryboard>                                                </DataTrigger.EnterActions>                                            </DataTrigger>                                        </Style.Triggers>                                    </Style>                                </Border.Style>

This problem can be solved perfectly, but the specific reasons still need to be studied.

WPF background property does not point to a dependencyobject in path' (0). (1 )'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.