8

午前中ずっとこれに頭をぶつけていました。

基本的に、私はリストボックスを持っており、長時間実行されているプロセス中に人々が選択を変更できないようにしたいのですが、それでもスクロールできるようにします。

解決:

すべての答えは良かったです。それが最も簡単だったので、マウスイベントを飲み込みました。PreviewMouseDown と PreviewMouseUp を 1 つのイベントに配線し、backgroundWorker.IsBusy をチェックし、イベント引数の IsHandled プロパティが true に設定されているかどうかを確認しました。

4

12 に答える 12

2

自動スクロールが有効になっているScrollViewerに無効なリストボックスを配置すると、目的の効果が得られることがわかりました。

于 2013-02-26T12:38:40.970 に答える
2

申し訳ありませんが、ほぼ2年が経ちましたが、DataTriggerを使用するこのソリューションはさらに簡単だと思います. プロパティ値に基づいてデータバインドされた ListBox アイテムを無効にする方法は?

于 2010-12-14T01:15:30.773 に答える
1

私はこのソリューションを使用しました。これは本当に簡単で、完全に機能します。

SurfaceListBoxItem itemに入れるたびにListbox、次のようにします。

item.IsHitTestVisible = false;
于 2010-06-09T11:50:46.003 に答える
0

検討する価値のあるもう1つのオプションは、ListBoxItemsを無効にすることです。これは、次のスニペットに示すようにItemContainerStyleを設定することで実行できます。

<ListBox ItemsSource="{Binding YourCollection}">
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="IsEnabled" Value="False" />
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

テキストを灰色にしたくない場合は、次のキーを使用してスタイルのリソースにブラシを追加することにより、無効な色を指定できます:{x:StaticSystemColors.GrayTextBrushKey}。もう1つの解決策は、ListBoxItemコントロールテンプレートをオーバーライドすることです。

この質問はこれとほとんど同じです。ListBox.SelectionMode=“ None”はありませんが、リストボックスでの選択を無効にする別の方法はありますか?私の答えは同じです。

于 2011-02-16T02:08:09.067 に答える
0

私にとって非常にシンプルで簡単な解決策が見つかりました。それがあなたにとってもうまくいくことを願っています

<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
     <Setter Property="Focusable" Value="False"/>
 </Style>

于 2012-01-17T11:52:16.453 に答える
0

http://www.codeproject.com/Tips/60619/Scrollable-Disabled-ListBox-in-WPFを使用した完全な回答

スタイル:

<Style TargetType="{x:Type local:CustomListBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:CustomListBox}">
                <Border SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="1">
                    <ScrollViewer IsEnabled="True">
                        <ItemsPresenter IsEnabled="{Binding Path=IsEnabledWithScroll,  RelativeSource={RelativeSource TemplatedParent}}"  SnapsToDevicePixels="{TemplateBinding  UIElement.SnapsToDevicePixels}"/>
                    </ScrollViewer>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

クラス

public class CustomListBox : ListBox
{
    public bool IsEnabledWithScroll
    {
        get { return (bool)GetValue(IsEnabledWithScrollProperty); }
        set { SetValue(IsEnabledWithScrollProperty, value); }
    }

    public static readonly DependencyProperty IsEnabledWithScrollProperty =
        DependencyProperty.Register("IsEnabledWithScroll", typeof(bool), typeof(CustomListBox), new UIPropertyMetadata(true));
}

次に、ListBox で IsEnabled を設定する代わりに、代わりに IsEnabledWithScroll を使用します。リストボックスが有効または無効の場合、スクロールは機能します。

于 2016-03-08T13:39:16.607 に答える
0

さて、私はこの機能を提供する素晴らしい方法を見つけました。私がしたことは、listBox の DataTemplate で、ページをソースとして使用して、親レイアウトの enable プロパティをブール値フラグにバインドしたことです。

ステップ 1 - ページにx:Name属性を指定します。使用しているページがベース ページで拡張されている場合は、ベース ページが抽象クラスではなく、引数のないデフォルト コンストラクターを持っていることを確認してください。

<Page x:Class="OPMS.Views.Registration"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    x:Name="MainPage"
    d:DesignWidth="1024"
    Title="Registration"
>

ステップ 2 - Page を DataTemplate 親レイアウト アイテムの IsEnabled プロパティのソースとして使用する

<ListBox Grid.Row="2"
    ItemsSource="{Binding TestGroups}"
    AlternationCount="2"
    Padding="0"
    Margin="10,5,10,10"
>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <CheckBox Content="{Binding Name}"
                IsChecked="{Binding IsSelected}"
                IsEnabled="{Binding Source={x:Reference MainPage}, Path=DataContext.BindingVariableHere}"
            />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
于 2020-12-24T14:18:16.513 に答える
0

この特定の猫の皮を剥ぐ方法はたくさんあるようです。XAML で を設定IsHitTestVisibleすることで、必要なものが正確に得られることがわかりました。ItemsContainerStyle

<ListBox IsHitTestVisible="true" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True">
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="IsHitTestVisible" Value="False" />
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>
于 2017-10-05T18:18:23.740 に答える