我有个问题。如何将ItemsSource属性绑定到NumericUpDown?这样就行不通了。谢谢!
<DataGrid ItemsSource="{Binding Articles}">
<DataGrid.Columns>
<DataGridTemplateColumn MinWidth="100"
Header="Amount"
MaxWidth="{Binding MinWidth, RelativeSource={RelativeSource Self}}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<mahApps:NumericUpDown Value="{Binding Amount, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="ValueChanged">
<i:InvokeCommandAction CommandParameter="{Binding}"
Command="{Binding DataContext.RefreshValuesCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</mahApps:NumericUpDown>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>编辑
第一:悬臂(西班牙语)=金额(英文)


发布于 2017-01-09 15:36:52
如果Amount属性是在文章属性相同的类中定义的,则应该绑定到DataContext (DataContext.Amount)的DataGrid:
<mahApps:NumericUpDown Value="{Binding DataContext.Amount, UpdateSourceTrigger=PropertyChanged,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="ValueChanged">
<i:InvokeCommandAction CommandParameter="{Binding}"
Command="{Binding DataContext.RefreshValuesCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</mahApps:NumericUpDown>如果在数据对象(项目或您所称的任何内容)类中定义了Amount属性,那么它就是:
<mahApps:NumericUpDown Value="{Binding Amount}">编辑:您还应该设置绑定到PropertyChanged的UpdateSourceTrigger:
<mahApps:NumericUpDown Value="{Binding Amount, UpdateSourceTrigger=PropertyChanged}" />https://stackoverflow.com/questions/41550798
复制相似问题