Search code examples
c#wpfwpf-controls

WHY System.Windows.Markup.XamlParseException: ''Provide value on 'System.Windows.StaticResourceExtension' threw an exception. ERROR


Idk why I have this error:

enter image description here

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <Window.Resources>
        <SolidColorBrush x:Key="MyBrush" Color="SkyBlue"/>
        <Style x:Key="MyButtonStyle" TargetType="Button">
            <Setter Property="Background" Value="{StaticResource MyBrush}"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="FontSize" Value="16"/>
            <Setter Property="Padding" Value="10"/>
        </Style>
    </Window.Resources>


    <Grid>
        <Button Content="Click Me" Style="{StaticResource MyButtonStyle}" />
    </Grid>
</Window>

It's problem of visual studio? OR WHAT? I really don't understand this error? Why? Whats wrong. Please help me!


Solution

  • Just change version of .NET from 8 to 9 and all works) IDK why...