[WPF学習] 12. VisualBrushを動的にバインドする

オリジナル: [WPFラーニング] 12. VisualBrushを動的にバインド

要件は非常に単純です。つまり、テキストボックスにはプレースホルダー効果が必要です。「名前」は中国語で表示され、「名前」は英語で表示されるため、次のコードを使用します。

        <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>

次に、動的に英語のリソースに切り替えると、彼はまだ中国語のハローであることがわかりました。後で、次のコードに変更しても問題ありませんでした。理由がわかりません。

                  <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>

おすすめ

転載: www.cnblogs.com/lonelyxmas/p/12749008.html