C# x:名称';xaml中的d TextBlock未显示在代码隐藏中
尝试在我的代码隐藏中访问下面的文本块,以便以编程方式设置其文本。但是,x:name“HintText”不会显示。是因为它是文本框样式的一部分吗C# x:名称';xaml中的d TextBlock未显示在代码隐藏中,c#,xaml,C#,Xaml,尝试在我的代码隐藏中访问下面的文本块,以便以编程方式设置其文本。但是,x:name“HintText”不会显示。是因为它是文本框样式的一部分吗 <TextBox x:Name="SearchTextBox" Grid.Column="2" TextAlignment="Left" VerticalContentAlignment="Center" BorderThickn
<TextBox x:Name="SearchTextBox"
Grid.Column="2"
TextAlignment="Left"
VerticalContentAlignment="Center"
BorderThickness="0"
FontFamily="{DynamicResource RobotoFont}"
Foreground="{DynamicResource EclipseGray}"
FontSize="18"
TextChanged="SearchTextBox_OnTextChanged"
GotFocus="SearchTextBox_OnGotFocus"
LostFocus="SearchTextBox_OnLostFocus">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="White"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text.IsEmpty}" Value="True">
<Setter Property="Background">
<Setter.Value>
<VisualBrush AlignmentX="Left" AlignmentY="Center" Stretch="None">
<VisualBrush.Visual>
<TextBlock x:Name="HintText"
VerticalAlignment="Center"
FontSize="16"
Foreground="LightGray"
FontFamily="{DynamicResource RobotoFont}">
Search for a word or phrase...
</TextBlock>
</VisualBrush.Visual>
</VisualBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
搜索一个单词或短语。。。
我也有类似的问题。尝试保存这些文件,这样可以让Intellisense找到它。它解决了我的问题。找到了一个链接,指向一位同事的答案。
马丁·施密特的答案就是我使用的答案。注意到之前的实现可能也取自此链接。但它隐藏了对提示文本的访问,因此无法在代码中进行更改。这个解决方案简单得多
我的代码现在如下所示:
<Grid Background="White" HorizontalAlignment="left" VerticalAlignment="Center" >
<TextBox x:Name="SearchTextBox"
TextAlignment="Left"
VerticalContentAlignment="Center"
BorderThickness="0"
FontFamily="{DynamicResource RobotoFont}"
Foreground="{DynamicResource EclipseGray}"
FontSize="18"
TextChanged="SearchTextBox_OnTextChanged"
GotFocus="SearchTextBox_OnGotFocus"
LostFocus="SearchTextBox_OnLostFocus"/>
<TextBlock x:Name="HintText"
Margin="10,2"
MinWidth="50"
FontSize="16"
IsHitTestVisible="false"
FontFamily="{DynamicResource RobotoFont}"
Foreground="LightGray"
Visibility="{Binding ElementName=SearchTextBox, Path=Text.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}" />
</Grid>
</Gr