[WPF 學習] 12.動態綁定VisualBrush

需求很簡單,就是文本框想要個placeholder的效果,中文的時候顯示「姓名」,英文的時候顯示「Name」,因而有了如下代碼: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>

而後,動態切換成英文資源的時候,發現他仍是中文的,暈。後來改爲如下代碼就OK了,不知何解?ci

<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>
相關文章
相關標籤/搜索