Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在XAML中创建工作模板?_C#_Wpf_Xaml - Fatal编程技术网

C# 如何在XAML中创建工作模板?

C# 如何在XAML中创建工作模板?,c#,wpf,xaml,C#,Wpf,Xaml,我有EpaxnseItHome.xaml的下一个代码: <ListBox Name="peopleListBox" Grid.Column="1" Grid.Row="2" ItemsSource="{Binding Source={StaticResource ExpenseDataSource}, XPath=Person}" ItemTemplate="{StaticResource nameItemTemplate}"> </ListBox

我有EpaxnseItHome.xaml的下一个代码:

<ListBox Name="peopleListBox" Grid.Column="1" Grid.Row="2" 
     ItemsSource="{Binding Source={StaticResource ExpenseDataSource}, XPath=Person}"
     ItemTemplate="{StaticResource nameItemTemplate}">
    </ListBox>
    <Grid.Resources>
        <!-- Expense Report Data -->
        <XmlDataProvider x:Key="ExpenseDataSource" XPath="Expenses">
            <x:XData>
                <Expenses xmlns="">
                    <Person Name="Mike" Department="Legal">
                        <Expense ExpenseType="Lunch" ExpenseAmount="50" />
                        <Expense ExpenseType="Transportation" ExpenseAmount="50" />
                    </Person>
                </Expenses>
            </x:XData>
        </XmlDataProvider>
        <!-- Name item template -->
        <DataTemplate x:Key="nameItemTemplate">
            <Label Content="{Binding XPath=@Name}"/>
        </DataTemplate>            
    </Grid.Resources>


标签引用了
中的模板,但启动应用程序时返回一个错误,无法找到名为“nameItemTemplate”的资源。这个例子取自:

最后得到了它,在使用之前应该声明一个新模板。所以,为了解决这个问题,我把
..
换成了
..