【问题标题】:Defining Windows Store app Resources in XAML在 XAML 中定义 Windows 应用商店应用资源
【发布时间】:2014-10-02 19:28:15
【问题描述】:
<Page x:Class="Myprog.StartPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Myprog"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>
    <DataTemplate x:Key="ItemTemplate2">
        <Border BorderThickness="1" Height="36" Width="598" Margin="0 -5" Padding="2" BorderBrush="#FFE2E2E2">
            <Grid Background="#eee" KeyDown="Grid_KeyDown_1">
                <Grid.Resources>
                    <local:strConverter x:Name="sameera1"/>
                </Grid.Resources>
                <TextBlock TextWrapping="Wrap" Text="{Binding ProductDesc,Converter={StaticResource sameera1}}" Margin="0,0,227,0" Foreground="Black" Padding="6,5,0,0"/>
            </Grid>
        </Border>
    </DataTemplate>
</Page.Resources>

and then other elements...

在我的代码中,我在名称空间 Myprog.StartPage 中定义了 strConverter 类。 startPage 是包含设计的页面。

我已经使用这个资源 strConverter 来修改“ProductDesc”的值。

<Grid.Resources>
   <local:strConverter x:Name="sameera1"/>
</Grid.Resources>

编译时会显示以下错误消息..

命名空间“using:Myprog”中不存在名称“strConverter”。

我如何解决这个问题??

【问题讨论】:

  • strConverter 类的确切命名空间定义是什么?
  • 命名空间是Myprog
  • 等等,现在我看到了问题所在。写一个答案。

标签: xaml c#-4.0 windows-store-apps


【解决方案1】:

当你想消费一个资源时,你需要为那个资源声明一个键。

所以你应该把你的资源声明改成这样:

<Grid.Resources>
   <local:strConverter x:Key="sameera1"/>
</Grid.Resources>

那么 name 属性在 ResourceDictionary 中没有意义。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    相关资源
    最近更新 更多