相关疑难解决方法(0)

阻止用户取消选择ListBox中的项目?

我有一个包含大量项目的ListBox.用户可以单击项目以编辑其内容.如何阻止用户取消选择所有项目?即,用户不应该没有选择任何东西.

c# wpf xaml

8
推荐指数
1
解决办法
3060
查看次数

WPF MVVM ListBox中的多个选择

我有一个包含文件名的ListBox.现在我需要从这个ListBox获取所选项目的数组.我在这里找到了一些答案,但它们都没有为我工作.我正在使用Caliburn Micro框架.

这是我的观点:

<Window x:Class="ProgramsAndUpdatesDesktop.Views.DeleteHistoryView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:ProgramsAndUpdatesDesktop.Views"
    mc:Ignorable="d"
    ResizeMode="CanResizeWithGrip"
    MaxWidth="300"
    MinWidth="300"
    MinHeight="500"
    Title="DeleteHistoryView" Height="500" Width="300">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="30" />
    </Grid.RowDefinitions>
    <StackPanel Grid.Column="0" Grid.Row="0">
        <ListBox x:Name="DeleteHistoryListBox" SelectedItem="{Binding Path=DeleteHistorySelectedItem}" 
                 ItemsSource="{Binding DeleteHistoryListBox, NotifyOnSourceUpdated=True}" 
             SelectionMode="Multiple">
        </ListBox>
    </StackPanel>
    <StackPanel Grid.Column="0" Grid.Row="1">
        <Button x:Name="DeleteHistoryButtonAction">Delete</Button>
    </StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)

这是我的ViewModel:

class DeleteHistoryViewModel : Screen
{
    string historyFolderPath = Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["HistoryFolderPath"]);

    private ObservableCollection<string> deleteHistoryListBox = new ObservableCollection<string>();
    public ObservableCollection<string> DeleteHistoryListBox
    {
        get { return deleteHistoryListBox; }
        set { deleteHistoryListBox …
Run Code Online (Sandbox Code Playgroud)

wpf listbox mvvm multipleselection caliburn.micro

6
推荐指数
1
解决办法
1万
查看次数

不允许在ListBox中取消选择/取消选择

有没有办法配置WPF ListBox,以便取消选择/取消选择项目?总是选择一个项目?

ListBox对一个人的约束力ObservableCollection<MyClass>.

.net c# wpf xaml

3
推荐指数
1
解决办法
3504
查看次数

标签 统计

wpf ×3

c# ×2

xaml ×2

.net ×1

caliburn.micro ×1

listbox ×1

multipleselection ×1

mvvm ×1