【发布时间】:2013-07-01 02:33:25
【问题描述】:
您好,我想将按钮与其他 listView.Item 绑定。我想要的是像我们在stackoverflow上拥有的东西。 但我有增加/减少价值的问题。我有事件 Click 但我不知道如何在列表中获取相应的项目并增加/减少值。
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label Width="706" Height="75" Content="{Binding feedback}"/>
<StackPanel Orientation="Vertical">
<Button Name="buttonUp" Content="^" Command="{Binding upVoteCommand}" />
<Label HorizontalContentAlignment="Center" Width="50" Content="{Binding grade}"/>
<Button Name="buttonDown" Content="v" Command="{Binding upVoteCommand}"/>
</StackPanel>
</StackPanel>
<Label>-</Label>
</StackPanel >
编辑
class A {
public string feedback {
get;
set;
}
public int grade {
get;
set;
}
private ICommand _upVoteCommand;
private ICommand _downVoteCommand;
public ICommand upVoteCommand {
get {
return _upVoteCommand;
}
set {
_upVoteCommand = value;
}
}
public ICommand downVoteCommand {
get {
return _downVoteCommand;
}
set {
_downVoteCommand = value;
}
}
}
编辑我使用了这个按钮。命令但它仍然无法正常工作。我不知道如何处理这些命令。
【问题讨论】:
-
以与您在项目中绑定
feedback绑定Button.Command到upVote和downVote命令相同的方式,并在那里增加/减少feedback -
好的,我会试试的。我不知道 Command 属性。
-
您是否使用了一些 MVVM 框架或实现了
ICommand? -
不。我正在学习 wpf 中的工作原理。我想学习MVVM,但是在我对wpf有点了解之后。
-
你的 onClick 代码是什么样子的,当我们这样做的时候,你设置了 datacontext 吗?
标签: c# wpf data-binding