[UWP]主题自定义控件,Generic.xaml样式未应用于设计器中。 [英] [UWP] Themed Custom Control, Generic.xaml style is not applied in designer.

查看:78
本文介绍了[UWP]主题自定义控件,Generic.xaml样式未应用于设计器中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我正在尝试创建一个可以重复使用的UWP控件。它位于一个控件库中,其样式为Themes / Generic.xaml。

I'm trying to create an UWP control that I can reuse. It lives in a control library with a style in Themes/Generic.xaml.

如果我将应用程序项目中的控件添加到我的MainPage.xaml中。设计器(VS和Blend)只显示控件的位置,但实际上并没有使用Generic.xaml中定义的样式。

If I add that control in the application project to my MainPage.xaml. The designer (VS and Blend) only shows an outline of where the control is, but does not actually use the style that is defined in Generic.xaml.

但是如果我运行程序那么它会正确显示。

However if I run the program then it gets displayed correctly.

让设计师知道如何找到并应用该风格的正确方法是什么?

What's the correct way of letting the designer know how to find and apply that style?

谢谢,

Markus

推荐答案

Hi Tokter,

Hi Tokter,

>>"让设计师知道如何找到并应用该风格的正确方法是什么?"

>>" What's the correct way of letting the designer know how to find and apply that style?"

根据我的经验,你可以使用"ms-appx:///"从app包中获取样式文件。我为您制作了一个代码示例。

In my experience, you could use "ms-appx:///" to get the style file from app package. I have made a code sample for you.

请参考我的以下代码示例和屏幕截图以供参考:

Please refer to my following code sample and screenshot for reference:

<!--generic.xaml-->
    <ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >
    <Style TargetType="Button">
        <Setter Property="Background" Value="Red"></Setter>
    </Style>
</ResourceDictionary>


<UserControl
    x:Class="MyControl.MyUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">
    
    <Grid>
        <Button Content="button"></Button>
    </Grid>
</UserControl>


<Page
    x:Class="AppStyle.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:AppStyle"
    xmlns:mycontrol="using:MyControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ms-appx:///MyControl/Themes/Generic.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Page.Resources>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <mycontrol:MyUserControl></mycontrol:MyUserControl>
    </Grid>
</Page>




最好的问候,

Xavier Eoro

Xavier Eoro


这篇关于[UWP]主题自定义控件,Generic.xaml样式未应用于设计器中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆