欢迎,欢迎,热烈欢迎。。。

设置TextBlock默认样式后,其他控件的Text相关属性设置失效问题

问题:

  • 定义了默认TextBlock样式后,再次自定义下拉框 or 其他控件 ,当内部含有TextBlock时,设置控件的字体相关样式无效,系统始终使用TextBlock设置默认样式

解决方案:

  • 为相关控件定义数据模板,为内部TextBlock添加样式资源,指向默认资源。

具体为啥会有这种问题不清楚,解决方案参考:https://bbs.csdn.net/topics/390262033

    <DataTemplate x:Key="DataTemplate3">
        <Grid>
            <TextBlock >
                <TextBlock.Resources>
                    <Style TargetType="{x:Type TextBlock}"/>
                </TextBlock.Resources>
            </TextBlock>
        </Grid>
    </DataTemplate>

建议:

  • 尽量不要定义TextBlock默认样式,宁可在每个控件上设置Style属性,或者将使用TextBlock的地方改用Label,然后定义Label的默认样式【不过个人觉得一般情况还是不要使用Label,毕竟TextBlock是最简的,消耗的电脑资源也最小】

解:奇葩史

posted @ 2019-01-12 16:50  奇葩史  阅读(714)  评论(0编辑  收藏  举报
Come On! 不要走。。。