首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NumericUpDown值绑定

NumericUpDown值绑定
EN

Stack Overflow用户
提问于 2017-01-09 15:00:18
回答 1查看 1.7K关注 0票数 0

我有个问题。如何将ItemsSource属性绑定到NumericUpDown?这样就行不通了。谢谢!

代码语言:javascript
复制
<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>

编辑

第一:悬臂(西班牙语)=金额(英文)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-09 15:36:52

如果Amount属性是在文章属性相同的类中定义的,则应该绑定到DataContext (DataContext.Amount)的DataGrid:

代码语言:javascript
复制
<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属性,那么它就是:

代码语言:javascript
复制
<mahApps:NumericUpDown Value="{Binding Amount}">

编辑:您还应该设置绑定到PropertyChanged的UpdateSourceTrigger:

代码语言:javascript
复制
<mahApps:NumericUpDown Value="{Binding Amount, UpdateSourceTrigger=PropertyChanged}" />
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41550798

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档