C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了C#Caliburn.Micro多项选择大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_675_0@
@H_675_0@
我在我的C# WPF项目中使用Caliburn.Micro,并且我在ListBox中成功使用了单选选项.如何在此方案中使用多个选择?

XAML:

<ListBox x:Name="Items">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Label Content="{Binding TimE}"/>
                    <Label Content="{Binding Desc}"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

码:

public BindableCollection<MyObject> Items
{
    get
    {
        var collection = new BindableCollection<MyObject>(_MyObject);
        return collection;
    }
}

public MyObject SELEctedItem
{
    get; set;
}

解决方法

将IsSELEcted属性添加到您的项目:

public class MyObject : PropertyChangedBase
{
    public datetiR_263_11845@e Time { get; set; }
    public String Desc { get; set; }

    bool _isSELEcted;
    public bool IsSELEcted
    {
        get { return _isSELEcted; }
        set
        {
            _isSELEcted = value;
            NotifyOfPropertyChange();
        }
    }
}

然后将绑定添加到此属性到ListBox

<ListBox x:Name="Items" SELEctionMode="Multiple">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Label Content="{Binding TimE}"/>
                    <Label Content="{Binding Desc}"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
        <ListBox.ItemContainerStyle>
            <Style TargetType="{x:Type ListBoxItem}" BasedOn="{Staticresource {x:Type ListBoxItem}}">
                <Setter Property="IsSELEcted" Value="{Binding IsSELEcted,Mode=TwoWay}" />
            </Style>
        </ListBox.ItemContainerStyle>
    </ListBox>

之后,您可以参视图模型中的选定项目:

BindableCollection<MyObject> _items = new BindableCollection<MyObject>();
    public BindableCollection<MyObject> Items
    {
        get
        {
            return _items;
        }
    }    

    public BindableCollection<MyObject> SELEctedItems
    {
        get
        {
            _SELEctedItems.Clear();
            _SELEctedItems.AddRange(Items.Where(mo => mo.IsSELEcted));
            return _SELEctedItems;           
        }
    }
@H_675_0@

大佬总结

以上是大佬教程为你收集整理的C#Caliburn.Micro多项选择全部内容,希望文章能够帮你解决C#Caliburn.Micro多项选择所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:ccaliburnmicro多项选择
猜你在找的C&C++相关文章
其他相关热搜词更多
phpJavaPython程序员load如何string使用参数jquery开发安装listlinuxiosandroid工具javascriptcap