【问题标题】:WP7 - The attachable property 'Resources' was not found in type 'PhoneApplicationPage'WP7 - 在“PhoneApplicationPage”类型中找不到可附加属性“资源”
【发布时间】:2014-05-06 10:16:12
【问题描述】:

我正在尝试创建底栏。在这个底部栏中有 4 个按钮。 现在我已经创建了底部栏,并且已经包含在所有页面中。它的工作..!!现在我想删除按钮的填充和闪烁。所以我有这样的尝试。

<UserControl x:Class="NewExample.BottomTabBar"  
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
 d:DesignHeight="100" d:DesignWidth="480"             
shell:SystemTray.IsVisible="True">

<phone:PhoneApplicationPage.Resources>
    <Style x:Key="ButtonStyle1" TargetType="Button">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
        <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
        <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
        <Setter Property="Padding" Value="10,3,10,5"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid Background="Transparent">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                                <VisualState x:Name="Pressed"/>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="{StaticResource PhoneTouchTargetOverhang}">
                            <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</phone:PhoneApplicationPage.Resources>

<Grid x:Name="BottomToolUIContainer" Height="100" Width="480">

    <Button Command="{Binding Button1}" Background="{Binding BackColor1}" Content="Test 1" Height="120" HorizontalAlignment="Left" Name="MyBeno" VerticalAlignment="Top" Width="140" Margin="-10,-10,0,0" />

    <Button Command="{Binding Button2}" Background="{Binding BackColor2}"  Content="Test 2" Height="120" HorizontalAlignment="Left" Margin="109,-10,0,0" Name="Search" VerticalAlignment="Top" Width="140" />

    <Button Command="{Binding Button3}" Background="{Binding BackColor3}"   Content="Test 3" Height="120" HorizontalAlignment="Left" Margin="228,-10,0,0" Name="MyBasket" VerticalAlignment="Top" Width="140" />

    <Button Command="{Binding Button4}" Background="{Binding BackColor4}"  Content="Test 4" Height="120" HorizontalAlignment="Left" Margin="347,-10,0,0" Name="MyInfo" VerticalAlignment="Top" Width="140" />


</Grid>

但我收到的错误是:-在“PhoneApplicationPage”类型中找不到可附加属性“资源”

请告诉我如何解决这个问题。提前致谢。

【问题讨论】:

    标签: xaml windows-phone-7 user-controls


    【解决方案1】:

    既然你有一个UserControl,你应该在&lt;UserControl.Resources&gt;而不是&lt;phone:PhoneApplicationPage.Resources&gt;中添加样式:

    <UserControl.Resources>
        <Style x:Key="ButtonStyle1" TargetType="Button">
            ........
            ........
        </Style>
    </UserControl.Resources>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-12
      • 2015-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-08
      • 2015-03-11
      相关资源
      最近更新 更多