[WPF Learning] 12. Dynamically bind VisualBrush

Original: [WPF Learning] 12. Dynamically bind VisualBrush

The requirement is very simple, that is, the text box wants a placeholder effect. It displays "Name" in Chinese and "Name" in English, so I have the following code:

        <TextBox>
            <TextBox.Style>
                <Style TargetType="TextBox">
                    <Style.Triggers>
                        <Trigger Property="Text" Value="">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <VisualBrush Opacity="0.3" Stretch="None" TileMode="None">
                                        <VisualBrush.Visual>
                                            <TextBlock Text="{DynamicResource Name}" FontSize="20"></TextBlock>
                                        </VisualBrush.Visual>
                                    </VisualBrush>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TextBox.Style>
        </TextBox>

Then, when dynamically switching to English resources, I found that he was still in Chinese, halo. Later, it was OK to change to the following code, I do n’t know why?

                  <TextBox>
                        <TextBox.Style>
                            <Style TargetType="TextBox">
                                <Style.Triggers>
                                    <Trigger Property="Text" Value="">
                                        <Setter Property="Background" Value="{DynamicResource VBName}"></Setter>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </TextBox.Style>
                    </TextBox>

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12749008.html