【问题标题】:How to move Grid Resources to theme file (UWP)如何将网格资源移动到主题文件 (UWP)
【发布时间】:2020-04-14 08:40:18
【问题描述】:

我有一个这样的网格

                <Grid>
                    <Grid.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="FontSize" Value="12px"/>
                            <Setter Property="FontWeight" Value="SemiBold"/>
                            <Setter Property="FontStretch" Value="Normal"/>
                            <Setter Property="FontStyle" Value="Normal"/>
                            <Setter Property="Foreground" Value="#5D58F7"/>
                        </Style>
                    </Grid.Resources>
                    <uctrl:sr ></uctrl:sr>
                </Grid>

哪个工作正常。现在我想将这些样式移动到我的主题文件中。为了实现这一点,我做了这样的事情。

在theme.xaml中

    <Style x:Key="mystyleinsidethemefile" TargetType="TextBlock">
    <Setter Property="FontSize" Value="12px"/>
    <Setter Property="FontWeight" Value="SemiBold"/>
    <Setter Property="FontStretch" Value="Normal"/>
    <Setter Property="FontStyle" Value="Normal"/>
    <Setter Property="Foreground" Value="#5D58F7"/>
   </Style>

在我的页面内

                    <Grid Height="36" >
                    <Grid.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="Style" Value="{StaticResource mystyleinsidethemefile}"/>
                        </Style>
                    </Grid.Resources>
                    <uctrl:sr ></uctrl:sr>
                </Grid>

对我来说一切都很好,但这会引发错误,如图所示

我该如何解决这个问题?

【问题讨论】:

    标签: c# .net xaml uwp


    【解决方案1】:

    最低限度的回答

    在Style.BasedOn中设置mystyleinsidethemefile,或许可以让它工作。

    <Grid Height="36">
        <Grid.Resources>
            <Style TargetType="TextBlock" BasedOn="{StaticResource mystyleinsidethemefile}">
    
            </Style>
        </Grid.Resources>
        <uctrl:sr ></uctrl:sr>
    </Grid>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-28
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 2017-12-05
      • 2020-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多