[英]How to bind Custom attached property to CheckBox.IsChekedProperty in code behind?
[英]Bind Custom Attached Property in Code or Styles/Templates
我有通過表格重復的WPF:
<WrapPanel local:RadioChecker.IsChecked="False">
<RadioButton Content="Yes" Height="16" GroupName = "rbgSeizure" Name="rbSeizureYes"
local:RadioChecker.IsChecked="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked}" />
<RadioButton Content="No" Height="16" GroupName = "rbgSeizure" Name="rbSeizureNo"
local:RadioChecker.IsChecked="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked}" />
</WrapPanel>
如何以相同的方式設置每個WrapPanel和每個RadioButton,而不必將上述local:...
復制並粘貼到每個控件上,該怎么辦?
我可以在下面的代碼中獲得每個類型控件:
GetLogicalChildCollection<RadioButton>(mainPanel)
.ForEach(rb =>
{
Binding binding = new Binding();
//binding.Source
});
但是我不確定如何設置綁定的/將自定義附加屬性附加到控件。
應該是這樣的:
GetLogicalChildCollection<RadioButton>(mainPanel).ForEach(
rb =>
{
var binding = new Binding
{
Path = new PropertyPath(RadioButton.IsCheckedProperty),
Source = rb
};
rb.SetBinding(RadioChecker.IsCheckedProperty, binding);
});
或這個:
GetLogicalChildCollection<RadioButton>(mainPanel).ForEach(
rb => rb.SetBinding(RadioChecker.IsCheckedProperty,
new Binding("IsChecked") { Source = rb }));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.