This error only appear when I added <ImageSource x:key="...">
image resource file</ImageSource>
into my <application.resources>
section. However the program working fine in runtime without any problem.
Before (original code => 0 error):
<Application.Resources>
<FontFamily x:Key="NotoBold">
fonts/NotoSerifCJKtc-Bold.otf#Noto Serif CJK TC Bold
</FontFamily>
<Style x:Key="HeaderTitle" TargetType="TextBlock">
<Setter Property="Grid.Column" Value="0" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="18" />
<Setter Property="FontFamily" Value="{StaticResource NotoBold}" />
<Setter Property="Foreground" Value="White" />
</Style>
... ...
... ...
... ...
</Application.Resources>
After (added ImageSource xkey='RedCircle1' => 1 error):
<Application.Resources>
<FontFamily x:Key="NotoBold">
fonts/NotoSerifCJKtc-Bold.otf#Noto Serif CJK TC Bold
</FontFamily>
<ImageSource x:Key="RedCircle1">
images/sample/circleRed1.png
</ImageSource>
<Style x:Key="HeaderTitle" TargetType="TextBlock">
<Setter Property="Grid.Column" Value="0" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="18" />
<Setter Property="FontFamily" Value="{StaticResource NotoBold}" />
<Setter Property="Foreground" Value="White" />
</Style>
... ...
... ...
... ...
</Application.Resources>
The error hint appear on <Style x:Key="HeaderTitle" ... >
. If I change the setter value="{StaticResource NotoBold}" to something else(e.g. value="Verdana") the error will gone.
The error message: MarkupExtension is not valid for Setter.Value. The only supported MarkupExtension types are DynamicResourceExtension and BindingBase or derived types.
UPDATE
My .Net version is 4.8.03752, Visual Studio 2019 version is 16.8.3. All my resource files(Noto font and circleRed1.png) their build actions are "Resources".
Step to re-produce the problem.
<application.resources>
section.
(Until this step everything still fine no any error message appear.)My temporary solution:
Now everytime after the debugging, I have to fix everything again, for else my xaml designer view won't display correctly(some controls their style attribute won't take effect).
Please try to modify the code like the following:
<Setter Property="FontFamily" Value="{DynamicResource NotoBold}" />
A StaticResource will be resolved and assigned to the property during the loading of the XAML which occurs before the application is actually run. It will only be assigned once and any changes to resource dictionary ignored.
A DynamicResource assigns an Expression object to the property during loading but does not actually lookup the resource until runtime when the Expression object is asked for the value. This defers looking up the resource until it is needed at runtime. You could analyze whether to use DynamicResource or StaticResource according to the specific situation