Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Caliburn微绑定属性到带参数的方法_C#_Wpf_Mvvm_Data Binding_Caliburn.micro - Fatal编程技术网

C# Caliburn微绑定属性到带参数的方法

C# Caliburn微绑定属性到带参数的方法,c#,wpf,mvvm,data-binding,caliburn.micro,C#,Wpf,Mvvm,Data Binding,Caliburn.micro,我在应用程序中使用Caliburn.Micro。 我有这个列表框 <ListBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Source={x:Static models:Tags.AvailableTags}}"> <ItemsControl.ItemTemplate> <DataTemplate> <CheckBox Content="{Binding Name}"

我在应用程序中使用Caliburn.Micro。 我有这个列表框

<ListBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Source={x:Static models:Tags.AvailableTags}}">
  <ItemsControl.ItemTemplate>
    <DataTemplate>
      <CheckBox Content="{Binding Name}" IsChecked="{Binding ???}"/>
    </DataTemplate>
  </ItemsControl.ItemTemplate>
</ListBox>


基本上,我想将复选框的IsChecked属性绑定到DataContext的方法。我该怎么做呢?我知道如何在Caliburn.Micro中绑定事件,但我从未将方法绑定到属性。该方法还有一个属性。

您应该将视图中的ListBox集合绑定到具有要显示的属性的BindableCollection,即Name和Enabled

public class MyCollection
{ 
    public string Name { get; set; }
    public bool Checked { get; set; }
}
然后在视图中,将模型绑定到MyCollection对象集合:

public class YourViewModel : Screen
{
    private readonly IEventAggregator _Aggregator;
    private BindableCollection<MyCollection> tags= new BindableCollection<MyCollection>();

    public YourViewModel(IEventAggregator aggregator)
    {
        if (aggregator == null)
            throw new ArgumentNullException("aggregator");
        _Aggregator = aggregator;
        _Aggregator.Subscribe(this);
    }

    public BindableCollection<MyCollection> AvailableTags
    {
        get
        {
            if (tags== null)
                tags= new BindableCollection<MyCollection>();

            return tags;
        }
        set
        {
            tags= value;
            NotifyOfPropertyChange(() => MyCollection);
        }
    }  
}
公共类YourViewModel:屏幕
{
私有只读IEventagegrator\u聚合器;
私有BindableCollection标记=新建BindableCollection();
公共视图模型(IEventAggregator聚合器)
{
if(聚合器==null)
抛出新的ArgumentNullException(“聚合器”);
_聚合器=聚合器;
_聚合器。订阅(此);
}
公共BindableCollection可用标记
{
得到
{
if(标记==null)
tags=新的BindableCollection();
返回标签;
}
设置
{
标签=价值;
通知属性更改(()=>MyCollection);
}
}  
}
由于您也在使用标准的WPF列表框,Caliburn允许您根据约定将集合绑定到视图:

我的大脑快要爆炸了”))您不能将属性绑定到方法。(更准确地说,你想实现什么?)