我正在使用2资源字典Dictionary1.xaml
,Dictionary2.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>
在这个页面,请建议我如何使用这些字典和词典合并控制TextBox
在MainPage.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或任何页面中使用它吗?
例如,您在外部文件中以以下方式定义了外部资源。
<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] 删除。
我来说两句