Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Uwp 如何使用引用类库中使用自己的style.xaml文件的控件_Uwp_User Controls_Styles - Fatal编程技术网

Uwp 如何使用引用类库中使用自己的style.xaml文件的控件

Uwp 如何使用引用类库中使用自己的style.xaml文件的控件,uwp,user-controls,styles,Uwp,User Controls,Styles,因此,我构建了一个类库(通用windows),以便在尽可能多的应用程序中重用我的所有控件 我已经写了我所有的控件,现在我想使用它们,但是当我在我的实际应用程序中使用这些控件时,设计器中断了,我无法构建应用程序 这是错误消息: 这仅仅意味着找不到我的样式文件 因此,我的解决方案的结构如下: 样式将在示例控件中使用,如下所示: <UserControl.Resources> <ResourceDictionary> <Reso

因此,我构建了一个类库(通用windows),以便在尽可能多的应用程序中重用我的所有控件

我已经写了我所有的控件,现在我想使用它们,但是当我在我的实际应用程序中使用这些控件时,设计器中断了,我无法构建应用程序

这是错误消息:

这仅仅意味着找不到我的样式文件

因此,我的解决方案的结构如下:

样式将在示例控件中使用,如下所示:

<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary  Source="/Styles/SampleStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
以下是我的示例项目: 作为文件

UserControl元素具有资源查找行为的特殊情况,因为它具有定义范围和使用范围的固有概念。从其定义范围引用XAML资源的UserControl必须能够在其自己的定义范围查找序列中支持该资源的查找,也就是说,它不能访问应用程序资源。从UserControl使用范围来看,资源引用被视为位于指向其使用页面根的查找序列中(就像从加载的对象树中的对象生成的任何其他资源引用一样),并且可以访问应用程序资源


因此,您应该将SampleStyle.xaml放在UserControl的同一根位置,也就是说SampleStyle.xaml文件应该放在您的Controls文件夹中。

我读了很多关于如何操作的页面,但这不是我从文本中理解的。。。但这完全奏效了^^谢谢你花时间研究这件事^^
<Page
    x:Class="SandBoxSampleApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SandBoxSampleApp"
    xmlns:SampleControls="pack://application:,,,/SandBoxClassLibrary:component/Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:UsingSampleControls="using:SandBoxClassLibrary.Controls"
    >
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <UsingSampleControls:SampleUserControl/>
    </Grid>
</Page>
xmlns:SampleControls="pack://application:,,,/SandBoxClassLibrary:component/Controls"