【发布时间】:2015-12-22 21:33:18
【问题描述】:
我有一个 GridView,带有这个项目模板 (XAML):
<DataTemplate x:DataType="local:MyClass">
<TextBlock Text="{x:Bind MyString}"/>
<Button Command="{x:Bind command}"/>
</DataTemplate>
这里是MyClass (C++/CX)
public ref class MyClass sealed
{
public:
MyClass();
property Platform::String^ MyString
{
String^ get()
{
return mystring;
}
}
property ICommand^ command = ref new DelegateCommand(ref new ExecuteDelegate(this, &implementcommand), nullptr);
private:
String^ mystring;
void implementcommand(Platform::Object^ param);
}
DelegateCommand 函数是从此示例中提取的,未经修改:https://code.msdn.microsoft.com/windowsapps/Command-binding-inside-3cef5eea
现在,如果我单击网格视图中的任何按钮,它将调用implementcommand。但是,我想让implementcommand 对 TextBlock 控件做一些事情,例如更改文本的内容。从mainpage类内的任何函数,如果它不在gridview内,它就像textBlock->Text = ref new String("hello");一样简单但是,由于控件在gridview内,而implementcommand函数在MyClass中,不是MainPage,我不知道该怎么做。
【问题讨论】:
标签: xaml gridview data-binding uwp c++-cx