簡體   English   中英

在UWP中無法在頁面級別使用樣式

[英]Unable to use the styles at page level in UWP

我為樣式文件創建了一個ResourcesDictionary,並且有一個MainPage.xaml 當我在mainpage.xaml中使用資源字典中的樣式時,由於“無法解決資源”而引發了錯誤。 您能否告訴我答案,如何在頁面級別而不是應用程序級別使用樣式。

提前致謝。

這是我的示例代碼:

<views:MvxWindowsPage
    x:Class="Sample.UWP.Views.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Model="using:Sample.Core.ViewModels"
    xmlns:local="using:Sample.UWP"
    xmlns:views="using:MvvmCross.WindowsUWP.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ig="using:Infragistics.Controls"
    xmlns:entities="using:Sample.Core.Business.Entities"
    mc:Ignorable="d" IsTabStop="False" d:DesignHeight="300" d:DesignWidth="400">

    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries Source="SampleStyle.xaml">
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Page.Resources>

    <Grid>
        <Grid.Background>
            <ImageBrush Stretch="None" ImageSource="Resources\activation_port_bg.png" AlignmentY="Top" AlignmentX="Center"/>
        </Grid.Background>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Margin="50,75,50,75" HorizontalAlignment="Center">
            <TextBox  BorderBrush="LightGray" x:Name="txt1" PlaceholderText="id" Background="White" Width="300"
                      Text="{Binding id, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
        </StackPanel>
        <StackPanel Grid.Row="0" Margin="50,175,50,75" HorizontalAlignment="Center">
            <Button Background="#FF30DABB" x:Name="btnSignin" Content="signin" Command="{Binding SigninCommand}" Width="300">
            </Button>
        </StackPanel>
        <StackPanel Margin="50,240,50,75" HorizontalAlignment="Left" Style="{StaticResource stackStyle}" VerticalAlignment="Top">
            <!--<Image x:Name="image" Height="100" Source="/Resources/activation_port_bg.png"/>-->
            <!--<Button Content="Button Style" Style="{StaticResource btnStyle}"/>-->
            <Button Content="Button Style" Style="{StaticResource btnStyle}">
                <Button.Template>
                    <ControlTemplate>
                        <Border Style="{StaticResource brdr}"/>
                    </ControlTemplate>
                </Button.Template>
            </Button>
        </StackPanel>

    </Grid>
</views:MvxWindowsPage>

和我的SampleStyle.xaml

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

    <!--sample test styles-->
    <ControlTemplate x:Key="sampleStyle">
        <Style TargetType="TextBox"/>
    </ControlTemplate>

    <!--Border styles-->
    <Style x:Key="brdr" TargetType="Border">
        <Setter Property="CornerRadius" Value="2,2,8,8"/>
    </Style>

    <!--Button styles-->
    <Style x:Key="btnStyle" TargetType="Button">
        <Setter Property="Width" Value="300"/>
        <Setter Property="Height" Value="40"/>
        <Setter Property="BorderThickness" Value="5" />
        <Setter Property="Foreground" Value="Blue" />
        <Setter Property="BorderBrush" >
            <Setter.Value>
                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                    <GradientStop Color="Yellow" Offset="0.0" />
                    <GradientStop Color="Red" Offset="0.25" />
                    <GradientStop Color="Blue" Offset="0.75" />
                    <GradientStop Color="LimeGreen" Offset="1.0" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
  <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Resources/Styles/SampleStyle1.xaml"/>
            <ResourceDictionary Source="/Resources/Styles/SampleStyle2.xaml"/>
            <ResourceDictionary Source="/Resources/Styles/SampleStyle3.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM