“StaticResourceExtension”对于 Setter.Value 无效。 - 安装VS2022后出现新错误

问题描述 投票:0回答:1

我正在创建一些 WPF(自学)。 我相信它是在 VS2021 中创建的,但是我的电脑死了(主板)。 我已经在新电脑上重新安装了所有内容并带来了备份,然后安装了 VS2022。

打开后,我的 app.xml 样式部分出现大量错误 (30)。 这工作正常,奇怪的是仍然可以运行和编译,但显然我没有做正确的事情。

有趣的是,有些部分有效,而其他部分则无效。 主要不起作用的是引用顶部的 SOLIDCOLORBRUSH,它正在为应用程序设置颜色。

主要错误是:

错误 XDG0062“StaticResourceExtension”对于 Setter.Value 无效。 唯一支持的 MarkupExtension 类型是 DynamicResourceExtension 和 BindingBase 或派生类型。

错误 XDG0062 资源“brdrTeal”具有不兼容的类型。

错误 XDG0062 'txtTitle' 资源未找到。

这些都是通过 {StaticResource XXXXX} 引用的

最后这一段出现了这个错误:

错误:

错误 XDG0062“{DependencyProperty.UnsetValue}”不是有效值 对于 'System.Windows.Controls.Control.Template' 属性 二传手。

代码:

<Style TargetType="{x:Type ComboBoxItem}">

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                        <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1">
                            <ContentPresenter />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" TargetName="Border" Value="{StaticResource Teal2}"/>
                                <Setter Property="BorderBrush" TargetName="Border" Value="#00827b"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>



<Style TargetType="{x:Type ComboBoxItem}">

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                        <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1">
                            <ContentPresenter />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" TargetName="Border" Value="{StaticResource Teal2}"/>
                                <Setter Property="BorderBrush" TargetName="Border" Value="#00827b"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    

我在下面包含了 app.xaml 文件的一部分,以查看我如何布置所有内容。 如果这是一种不正确的方法,我热衷于正确地做到这一点,因为我的意思是我现在刚刚学习这个。

<Application.Resources>
    <ResourceDictionary>
        <SolidColorBrush x:Key="Teal1" Color="#67DAD5" />
        <SolidColorBrush x:Key="Teal2" Color="#39c0c0" />
        <SolidColorBrush x:Key="Teal3" Color="#00bab3" />
        <SolidColorBrush x:Key="Teal4" Color="#00a09b" />
        <SolidColorBrush x:Key="Teal5" Color="#00827b" />

        <SolidColorBrush x:Key="mintGreen" Color="#a4e9c6" />

        <SolidColorBrush x:Key="Teal2Light" Color="#c9e9ea" />
        <SolidColorBrush x:Key="LightGrey" Color="#f6f6f6" />
        <SolidColorBrush x:Key="MidGrey" Color="#aaaaad" />
        <SolidColorBrush x:Key="DarkGrey" Color="#56565b" />
        <SolidColorBrush x:Key="Burgundy1" Color="#8C0F57" />
        <SolidColorBrush x:Key="Burgundy2" Color="#deb9c7" />
        <SolidColorBrush x:Key="activeAreaColour" Color="#c9e9ea"/>

           
    <Style TargetType="{x:Type Window}">
            <Setter Property="ShowInTaskbar" Value="false"/>
        </Style>



        <Style TargetType="{x:Type Image}" x:Key="toolTipImage">
            <Setter Property="RenderOptions.BitmapScalingMode" Value="Fant" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="Height" Value="20"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Margin" Value="10 10 0 0"/>
        </Style>



        <Style BasedOn="{StaticResource {x:Type DataGridColumnHeader}}" TargetType="{x:Type DataGridColumnHeader}" >
            <Setter Property="Background" Value="{DynamicResource Teal2}" />
            <Setter Property="Foreground" Value="white" />
            <Setter Property="BorderBrush" Value="{DynamicResource Teal5}"/>
            <Setter Property="BorderThickness" Value="1 1 1 1"/>
            <Setter Property="Margin" Value="-1,-1,0,0" />
            <Setter Property="Height" Value="28" />
            <Setter Property="Width" Value="auto"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>


        </Style>
        <Style TargetType="DataGridCell">
            <Setter Property="HorizontalContentAlignment" Value="Right" />

            <Style.Triggers>
                <Trigger Property="DataGridCell.IsSelected" Value="True">
                    <Setter Property="Background" Value="{DynamicResource Teal2Light}" />
                    <Setter Property="BorderBrush" Value="{DynamicResource Teal5}" />
                    <Setter Property="BorderThickness" Value="1" />
                    <Setter Property="Foreground" Value="black" />
                    <Setter Property="FontWeight" Value="Bold" />
                    <Setter Property="FontSize" Value="12"/>
                </Trigger>

            </Style.Triggers>

        </Style>


        <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="ToggleButton">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="20" />
                </Grid.ColumnDefinitions>
                <Border
                  x:Name="Border" 
                  Grid.ColumnSpan="2"
                  CornerRadius="2"
                  Background="{DynamicResource Teal5}"
                  BorderBrush="{DynamicResource Teal5}"
                  BorderThickness="2" />
                <Border x:Name="lrgBorder"
  Grid.Column="0"
  CornerRadius="2,0,0,2" 
  Margin="1" 
  Background="{DynamicResource Teal2Light}" 
  BorderBrush="{DynamicResource Teal2Light}"
  BorderThickness="0,0,1,0" />
                <Path 
      x:Name="Arrow"
      Grid.Column="1"     
      Fill="White"
      HorizontalAlignment="Center"
      VerticalAlignment="Center"
      Data="M 0 0 L 4 4 L 8 0 Z"/>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="ToggleButton.IsMouseOver" Value="true">
                    <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource Burgundy1}" />
                </Trigger>
                <Trigger Property="ToggleButton.IsChecked" Value="true">
                    <Setter TargetName="Border" Property="Background" Value="{StaticResource Teal5}" />
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter TargetName="Border" Property="Background" Value="{StaticResource Burgundy2}" />
                    <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource Burgundy1}" />
                    <Setter TargetName="lrgBorder" Property="Background" Value="{StaticResource LightGrey}" />
                    <Setter Property="Foreground" Value="{StaticResource Burgundy1}"/>
                    <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource Burgundy2}" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

        <ControlTemplate x:Key="ComboBoxTextBox" TargetType="TextBox">
            <Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" />
        </ControlTemplate>

        <Style x:Key="{x:Type ComboBox}" TargetType="ComboBox">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
            <Setter Property="MinWidth" Value="120"/>
            <Setter Property="MinHeight" Value="20"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ComboBox">
                        <Grid>
                            <ToggleButton 
                                Name="ToggleButton" 
                                Template="{StaticResource ComboBoxToggleButton}" 
                                Grid.Column="2" 
                                Focusable="false"
                                IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                                ClickMode="Press">
                            </ToggleButton>
                            <ContentPresenter
                                Name="ContentSite"
                                IsHitTestVisible="False" 
                                Content="{TemplateBinding SelectionBoxItem}"
                                ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                                ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                Margin="3,3,23,3"
                                VerticalAlignment="Center"
                                HorizontalAlignment="Left" />
                            <TextBox x:Name="PART_EditableTextBox"
                                Style="{x:Null}" 
                                Template="{StaticResource ComboBoxTextBox}" 
                                HorizontalAlignment="Left" 
                                VerticalAlignment="Center" 
                                Margin="3,3,23,3"
                                Focusable="True" 
                                Background="Transparent"
                                Visibility="Hidden"
                                IsReadOnly="{TemplateBinding IsReadOnly}"/>
                            <Popup 
                                Name="Popup"
                                Placement="Bottom"
                                IsOpen="{TemplateBinding IsDropDownOpen}"
                                AllowsTransparency="True" 
                                Focusable="False"
                                PopupAnimation="Slide">
                                <Grid 
                                  Name="DropDown"
                                  SnapsToDevicePixels="True"                
                                  MinWidth="{TemplateBinding ActualWidth}"
                                  MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                    <Border 
                                        x:Name="DropDownBorder"
                                        Background="{StaticResource Teal2Light}"
                                        BorderThickness="1"
                                        BorderBrush="{StaticResource Teal5}"/>
                                    <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
                                        <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                                    </ScrollViewer>
                                </Grid>
                            </Popup>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="HasItems" Value="false">
                                <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{StaticResource Burgundy1}"/>
                            </Trigger>
                            <Trigger Property="IsGrouping" Value="true">
                                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                            </Trigger>
                            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
                                <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
                                <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
                            </Trigger>
                            <Trigger Property="IsEditable"
           Value="true">
                                <Setter Property="IsTabStop" Value="false"/>
                                <Setter TargetName="PART_EditableTextBox" Property="Visibility"    Value="Visible"/>
                                <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
            </Style.Triggers>
        </Style>


        <Style TargetType="{x:Type ComboBoxItem}">

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                        <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1">
                            <ContentPresenter />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" TargetName="Border" Value="{StaticResource Teal2}"/>
                                <Setter Property="BorderBrush" TargetName="Border" Value="#00827b"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <LinearGradientBrush x:Key="NormalBrush" StartPoint="0,0" EndPoint="0,1">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#c9e9ea" Offset="0.0"/>
                    <GradientStop Color="#67DAD5" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>




        <Style x:Key="activeBackground" TargetType="Grid">
            <Setter Property="Background" Value="{DynamicResource Teal2}"/>
        </Style>

        <sys:Double x:Key="fntButton">18</sys:Double>
        <sys:Double x:Key="fntButtonSmall">12</sys:Double>

        <sys:Double x:Key="ftnTextBox">15</sys:Double>

        <Style x:Key="brdrTeal" TargetType="{x:Type Border}">
            <Setter Property="BorderBrush" Value="{StaticResource Teal2}"/>
            <Setter Property="BorderThickness" Value="1"/>
        </Style>


        <Style x:Key="activeArea" TargetType="{x:Type Grid}">
            <Setter Property="Background" Value="{StaticResource activeAreaColour}"/>
        </Style>


        <Style x:Key="brdrBurgundy" TargetType="{x:Type Border}">
            <Setter Property="BorderBrush" Value="{StaticResource Burgundy1}"/>
            <Setter Property="BorderThickness" Value="1"/>
        </Style>

        <Style  TargetType="{x:Type Label}">
            <Setter Property="Margin" Value="0 10 0 0"/>
            <Setter Property="HorizontalAlignment" Value="Right"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="FontWeight" Value="DemiBold"/>
        </Style>

        <!--#region TxtBoxes and passwordbox-->

        <Style x:Key="txtWhite" TargetType="{x:Type TextBox}">
            <Setter Property="FontSize" Value="{StaticResource ftnTextBox}"/>
            <Setter Property="Background" Value="White"/>
            <Setter Property="BorderBrush" Value="{StaticResource brdrTeal}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Margin" Value="5"/>
        </Style>

        <Style x:Key="txtGrey" TargetType="{x:Type TextBox}">
            <Setter Property="FontSize" Value="{StaticResource ftnTextBox}"/>
            <Setter Property="Background" Value="{StaticResource LightGrey}"/>
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="5 0 0 0"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Margin" Value="0 10 0 0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TextBox}">
                        <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                            <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="false">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ResourceKey=MidGrey}"/>
                                <Setter Property="BorderThickness" TargetName="border" Value="2"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ResourceKey=Teal2}"/>
                                <Setter Property="BorderThickness" TargetName="border" Value="2"/>
                            </Trigger>
                            <Trigger Property="IsFocused" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ResourceKey=Teal2}"/>
                                <Setter Property="Background" TargetName="border" Value="{StaticResource ResourceKey=Teal2Light}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter Property="Foreground" Value="{StaticResource ResourceKey=Burgundy1}"/>
                    <Setter Property="FontWeight" Value="DemiBold"/>
                </Trigger>
            </Style.Triggers>

        </Style>

        <Style x:Key="txtPassGrey" TargetType="{x:Type PasswordBox}">
            <Setter Property="FontSize" Value="{StaticResource ftnTextBox}"/>
            <Setter Property="Background" Value="{StaticResource LightGrey}"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type PasswordBox}">
                        <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                            <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ResourceKey=Teal2}"/>
                                <Setter Property="BorderThickness" TargetName="border" Value="2"/>
                            </Trigger>
                            <Trigger Property="IsFocused" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ResourceKey=Teal2}"/>
                                <Setter Property="Background" TargetName="border" Value="{StaticResource ResourceKey=Teal2Light}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter Property="Foreground" Value="{StaticResource ResourceKey=Burgundy1}"/>
                    <Setter Property="FontWeight" Value="DemiBold"/>
                </Trigger>
            </Style.Triggers>
        </Style>

        <!--#endregion -->


        


    </ResourceDictionary>
</Application.Resources>
wpf xaml visual-studio-2022 wpf-style
1个回答
0
投票

动态值需要DynamicResource。 改变例如

Background="{StaticResource Teal5}"

Background="{DynamicResource Teal5}"
© www.soinside.com 2019 - 2024. All rights reserved.