Share via

Missing theme resource on older Windows

Mike 1 Reputation point
2020-10-30T19:48:12.47+00:00

Some resources (e.g. AppBarButtonContentHeight) seem to be missing in older versions of Windows (in this case, it's not present in 1809 - at least, the runtime throws an exception). How can I add a default value for such a resource in case it is missing in a theme dictionary, but keep the themed resource if it's present in the system?

Developer technologies | Universal Windows Platform (UWP)
0 comments No comments

1 answer

Sort by: Most helpful
  1. Richard Zhang-MSFT 6,936 Reputation points Microsoft Employee Moderator
    2020-11-02T02:29:01.137+00:00

    Hello,

    Welcome to Microsoft Q&A.

    With the update of Windows 10 system and the addition of new features. The styles of UWP default controls will also be updated. Just like Acrylic Brush cannot be used in systems below 16299.

    In order to be compatible with lower version systems, XAML has a function: Conditional XAML.

    You can create different XAML styles for different system versions:

       <Page  
           x:Class="ConditionalTest.MainPage"  
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
           xmlns:contract5Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,5)">  
         
           <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
               <TextBlock contract5Present:Text="Hello, Conditional XAML"/>  
           </Grid>  
       </Page>  
    

    ---

    When you are known to be missing a resource value, you can create the resource in the project, but you cannot modify the system resource file (generic.xaml).

    Thanks.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.