无法解析资源“x” [重复]

The resource "x" could not be resolved [duplicate]

提问人:Simone Bruzzi 提问时间:11/15/2023 更新时间:11/16/2023 访问量:46

问:

主窗口 Xaml 和我对这一行有问题,但不知道为什么复活存在但找不到代码

<Grid Width="300" HorizontalAlignment="Left">
                    <TextBlock Margin="20 0" VerticalAlignment="Center" Foreground="#b0b9c6" IsHitTestVisible="False"
                               Panel.ZIndex="1" Text="Ricerca..."
                               Visibility="{Binding ElementName=txtRicerca , Path=Text.IsEmpty,Converter={StaticResource BoolToVis}}"/>

                    <TextBox x:Name="txtSearch" Style="{StaticResource textboxSearch }"/>

                    <Icon:PackIconMaterial Kind="Magnify" Width="15" Height="15" VerticalAlignment="Center"
                                           Margin="0 0 15 0" Foreground="#b0b9c6" HorizontalAlignment="Right"/>

                </Grid>

App.Xaml

 <Style x:Name="textboxSearch" TargetType="TextBox">
            <Setter Property="Background" Value="#ffffff"/>
            <Setter Property="Foreground" Value="#b0b9c6" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="FontSize" Value="12"/>
            <Setter Property="Padding" Value="15 10" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Margin" Value="0 10" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TextBoxBase">
                        <Border x:Name="border" CornerRadius="20" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"
                                BorderThickness="1" BorderBrush="#e0e6ed">
                            <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden"
                                          VerticalScrollBarVisibility="Hidden"/>
                        </Border>

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="BorderBrush" Value="#d9d9d9" TargetName="border"/>
                            </Trigger>

                            <Trigger Property="IsKeyboardFocused" Value="True">
                                <Setter Property="BorderBrush" Value="#d9d9d9" TargetName="border"/>
                            </Trigger>

                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

我试图 chenge 属性、更改名称、删除、分配给 athor 文本框,但 nothig 有效

C# WPF XAML

评论

0赞 Simone Bruzzi 11/15/2023
probl 与 <TextBox x:Name=“txtSearch” Style=“{StaticResource textboxSearch }”/>
0赞 Jonathan Willcock 11/15/2023
请改用<TextBox Name="txtSearch" ..
0赞 Clemens 11/16/2023
@JonathanWillcock 这是胡说八道,对不起。问题是缺少资源密钥。

答:

0赞 mm8 11/15/2023 #1

在文件中更改为:x:Namex:KeyApp.xaml

<Application ...>
    <Application.Resources>
        <Style x:Key="textboxSearch" TargetType="TextBox">
        ...
    </Application.Resources>
</Application>