我正在与 SyncFusion's TreeView 合作。我有一个带有三个单独的数据模板/自定义 View 单元格的 TreeView。在我的主 XAML 中,我有以下 TreeView 代码,它绑定(bind)到我的 DataTemplates。
SamplePage.xaml
<syncfusion:SfTreeView x:Name="treeView"
QueryNodeSize="TreeView_QueryNodeSize"
NodeSizeMode="Dynamic"
AutoExpandMode="RootNodesExpanded"
ChildPropertyName="SubFiles"
ItemsSource="{Binding ImageNodeInfo}" Indentation="0"
ItemTemplate="{StaticResource TemplateSelector}">
</syncfusion:SfTreeView>
我现在尝试将我的命令从我的数据模板之一(下面的代码)绑定(bind)到连接到我的页面的 View 模型,但我似乎无法连接我的数据绑定(bind)。大多数在线示例都在 View /viewModel 的同一 xaml 页面上显示数据模板。但是,我的代码使用数据模板选择器,这给我提供了更难的绑定(bind)路径。
示例模板.xaml
<ViewCell.BindingContext>
<local:SamplePage x:Key="SamplePage">
</local:SamplePage>
</ViewCell.BindingContext>
<ImageButton Aspect="AspectFill"
Grid.Row="0" Grid.Column="3"
HorizontalOptions="End"
WidthRequest="90" HeightRequest="90"
Source="{xaml:ImageResource plus_Icon}"
Command="{Binding Path=BindingContext.AddAsJobClickedCommand}, Source={x:Reference SamplePage}"
CommandParameter="{Binding treeView}"
/>
最佳答案
试试这个,可能您缺少命令的x:Reference
:
<ImageButton Aspect="AspectFill"
Grid.Row="0" Grid.Column="3"
HorizontalOptions="End"
WidthRequest="90" HeightRequest="90"
Source="{xaml:ImageResource plus_Icon}"
Command="{Binding Path=BindingContext.AddAsJobClickedCommand, Source={x:Reference treeView}}"
CommandParameter="{x:Reference treeView}"/>
注意:这里treeView
是SfTreeView的x:Name
查找Reference这里
关于c# - 如何将图像按钮命令从数据模板选择器绑定(bind)到 View 模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57599739/