如何在其他页面中使用App ResourceDictionary和MergedDictionaries-Windows Phone 8.1

安库什·马丹卡(Ankush Madankar)

我正在使用2资源字典Dictionary1.xamlDictionary2.xaml并且具有TextBox和的样式TextBlock我在App.xaml两个字典中都添加了这样的内容:

<Application
    x:Class="XAMLResources.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:XAMLResources">

    <Application.Resources>
        <SolidColorBrush x:Key="MyBrush" Color="Yellow" />

        <ResourceDictionary x:Key="dict" Source="Dictionary1.xaml"/>

        <ResourceDictionary x:Key="mergeDictionary">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Dictionary1.xaml" />
                <ResourceDictionary Source="Dictionary2.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

    </Application.Resources>

</Application>

现在,请帮助我使用页面中的那些资源:

<Page
    x:Class="XAMLResources.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
    >
    <StackPanel Margin="20,30,0,0">
        <TextBox Margin="0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Stretch"/>
    </StackPanel>
</Page>

在这个页面,请建议我如何使用这些字典和词典合并控制TextBoxMainPage.xaml

编辑 Dictionary1.xaml看起来像:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:XAMLResources">

    <Style x:Key="eText" TargetType="TextBox">
        <Setter Property="FontSize" Value="18"/>
        <Setter Property="FontFamily" Value="Segoe WP SemiLight"/>
        <Setter Property="TextWrapping" Value="Wrap"/>
        <Setter Property="Background" Value="#FAFAFA"/>
        <Setter Property="BorderBrush" Value="#D2D2D2"/>

    </Style>
</ResourceDictionary>

我可以eText在UserControl或任何页面中使用它吗?

Akshay Soam

例如,您在外部文件中以以下方式定义了外部资源。

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <SolidColorBrush x:Key="TitleBrush" Color="DarkViolet" />
    <SolidColorBrush x:Key="ContentBrush" Color="Black" />
</ResourceDictionary>

编辑

根据您的说法,我已经在App.xaml中定义了它们

<Application
    x:Class="App2.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2">

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Dictionary1.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

现在,我在普通的xaml页面中使用它。TextBlock中使用TitleBrush资源与在Dictionary1.xaml中实际存在其定义的资源相同。

<Page
    x:Class="App2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ColumnDefinitions >
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
        </Grid.RowDefinitions>

        <StackPanel>
            <TextBlock FontSize="20" Foreground="{StaticResource TitleBrush}" Text="Sample text" />
        </StackPanel>
    </Grid>
</Page>

要获得更多帮助,您可以参考此链接。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何确定Windows Phone 8(.1)上的蓝牙是否打开

来自分类Dev

如何在Windows Phone 8中使用图钉显示给定纬度和经度的地图

来自分类Dev

如何在Windows Phone 8中使用经度和纬度获取位置

来自分类Dev

如何在Windows Phone 8中合并音频和视频

来自分类Dev

对Windows Phone 8使用WNS

来自分类Dev

如何在Windows Phone 8中使用ProgressRing

来自分类Dev

如何在Windows Phone 8中使用Telegram API?

来自分类Dev

如何在Windows Phone 8中使用TargetNullValue?

来自分类Dev

如何在Windows Phone 8中使用Telegram API?

来自分类Dev

如何在Windows Phone 8的WebView中根据月份的日期和时间显示不同的html页面:

来自分类Dev

Windows Phone 8 App升级到Windows Phone 8.1

来自分类Dev

如何在Windows Phone中交叉引用MergedDictionaries?

来自分类Dev

arduino(microusb)和Windows Phone 8 / 8.1

来自分类Dev

Windows Phone 8和带键盘的接头

来自分类Dev

FastCV和Windows Phone 8(C#)

来自分类Dev

Windows Phone 8和8.1的支持通知

来自分类Dev

如何使用静态库(Windows Phone 8)

来自分类Dev

如何在Windows Phone 8中禁用页面过渡动画?

来自分类Dev

Windows Phone 8编辑标题枢纽页面

来自分类Dev

Windows Phone 8页面方向

来自分类Dev

使用phonegap在Windows Phone 8开发中出现Error1 0x8974002F

来自分类Dev

如何禁用Windows Phone 8的缩放

来自分类Dev

如何创建Windows Phone 8应用包?

来自分类Dev

如何阅读列表<>?Windows Phone 8

来自分类Dev

如何替换.txt文件Windows Phone 8

来自分类Dev

Windows Phone 8 Listpicker ItemTemplate未被使用

来自分类Dev

在Windows Phone 8上使用Cookie

来自分类Dev

Windows Phone 8记录

来自分类Dev

Windows Phone 8的LockScreen

Related 相关文章

热门标签

归档