checkbox wpf 绑定数组_WPF数据绑定CheckBox.IsChecked

本文探讨如何将WPF中CheckBox的IsChecked属性绑定到窗体的成员变量,以实现数据绑定。在尝试过程中,遇到了问题,即IsChecked的绑定无法正常工作。XAML代码中,CheckBox的IsChecked属性被绑定到ShowPending属性,但检查时发现ShowPending的值始终为false。解决方案提到需要为ShowPending添加DependencyProperty,以便在值改变时能正确更新。
摘要由CSDN通过智能技术生成

How would I bind the IsChecked member of a CheckBox to a member variable in my form?

(I realize I can access it directly, but I am trying to learn about databinding and WPF)

Below is my failed attempt to get this working.

XAML:

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Title" Height="386" Width="563" WindowStyle="SingleBorderWindow">

TabIndex="2" Margin="0,12,30,0"

Checked="checkBoxShowPending_CheckedChanged"

Height="17" Width="92"

VerticalAlignment="Top" HorizontalAlignment="Right"

Content="Show Pending" IsChecked="{Binding ShowPending}">

Code:

namespace MyProject

{

public partial class Form1 : Window

{

private ListViewColumnSorter lvwColumnSorter;

public bool? ShowPending

{

get { return this.showPending; }

set { this.showPending = value; }

}

private bool showPending = false;

private void checkBoxShowPending_CheckedChanged(object sender, EventArgs e)

{

//checking showPending.Value here. It's always false

}

}

}

解决方案

Note i added a name to , and changed the binding in your CheckBox. You will need to implement ShowPending as a DependencyProperty as well if you want it to be able to update when changed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值