开发者

WPF: Named Style can not be found in Resource

Exactly the below code works in a TEST project. But in my productive project It does not find the Resource, why this?

Wpf can not find this Style="{StaticResource bla}"

<TextBlock Height="23" HorizontalAlignment="Left" Margin="22,89,0,0"  开发者_StackOverflow中文版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>


In your style tag instead of name used key. you can find a resource with its key. change this to

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜