[WPF learning] 11. The dynamic binding VisualBrush

Demand is simply that you want to effect a placeholder text box, the Chinese when the show "Name", the English when the show "Name", so with 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, switching to English dynamic resource I found he was Chinese, and halo. Later changed to the following code OK, I do not know of reconciliation?

                  <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/catzhou/p/12658478.html