【发布时间】:2015-12-14 01:04:02
【问题描述】:
这是用于 UWP 的 C++/CX 和 XAML。假设我有一堂课:
public ref class foo
{
private:
String^ title;
String^ printstring;
public:
foo()
{
title = "this is my title";
printstring = "test";
}
property String^ Title
{
String^ get()
{
return title;
}
}
}
我有一个向量Platform::Collections::Vector<foo^>^ testbind。我还有一个返回该向量的属性。在我的 XAML 中,我有一个网格视图,其中 ItemSource 设置为 testbind 的属性,而 ItemTemplate 设置为:
<DataTemplate x:DataType="local:foo">
<StackPanel Height="100" Width="100">
<TextBlock Text="{x:Bind Title} TextWrapping="WrapWholeWords"/>
<Button x:Name=button/>
</StackPanel>
</DataTemplate>
如何做到这一点,以便当我单击按钮时,我可以在代码后面使用 printstring 做一些事情?在这个假设的场景中,所有的 Titles 和 printstrings 都是相同的,但在我的实际项目中,它们对于向量的每个成员都是不同的。
【问题讨论】:
标签: xaml gridview data-binding uwp c++-cx