以下代码正好在TEST项目中有效。但是在我的高效项目中它找不到资源,为什么会这样?
Wpf无法找到此Style="{StaticResource bla}"
<TextBlock Height="23" HorizontalAlignment="Left" Margin="22,89,0,0" Text="Keywords" VerticalAlignment="Top" />
<TextBox Style="{StaticResource bla}" Height="23" HorizontalAlignment="Left" Margin="22,109,0,0" VerticalAlignment="Top" Width="244">
<Binding Path="Tags" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<DataErrorValidationRule ValidatesOnTargetUpdated="False" ValidationStep="UpdatedValue" />
</Binding.ValidationRules>
</Binding>
</TextBox>
<UserControl.Resources>
<Style x:Name="bla" TargetType="TextBox">
<Setter Property="BorderBrush" Value="DarkBlue"/>
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Margin" Value="0,1,0,1" />
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<AdornedElementPlaceholder />
<Grid Margin="2,0,0,0">
<Ellipse Width="20" Height="20" Fill="Red"/>
<TextBlock Foreground="White" Text="X" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}" />
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
答案 0 :(得分:1)
在您的样式标记中,而不是使用名称键。你可以找到一个带有密钥的资源。 将此更改为