XAML:禁用容器中的所有元素,但滚动

本文关键字:元素 滚动 XAML | 更新日期: 2023-09-27 18:33:56

我有这个devExpress xaml元素(但任务是通用的,我认为它适合其他no-devExpress的情况):

<dxlc:LayoutControl Grid.Column="1" Orientation="Vertical" UseLayoutRounding="True" 
                            IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window},Path=DataContext.canEditImpianti}" 
                            DataContext="{Binding SelectedItem, ElementName=lst1}" Margin="0,10,0,0">

如您所见,我使用绑定布尔值将布局控件设置为启用/禁用。必要时,里面的所有文本字段都会被相应地禁用,但它也会禁用滚动(字段很多,我需要滚动才能查看它们)。

我想禁用所有输入,但保留滚动功能。我该怎么做?我也尝试过 IsManipulationEnabled 属性,但它似乎什么也没做。

这就是我定义滚动条的方式:

<ScrollViewer x:Name="scrollViewer" VerticalScrollBarVisibility="Auto" Width="Auto" Height="Auto">

显然,容器位于scrollViewer标签内。如何解决我的问题?

这是我的 XAML:

<ScrollViewer x:Name="scrollViewer" VerticalScrollBarVisibility="Auto" Width="Auto" Height="Auto">
    <Grid  x:Name="ext" Height="336">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="37"  />
                <RowDefinition  />
            </Grid.RowDefinitions>
            <dxe:SearchControl x:Name="searchControl" FilterCondition="Contains" FilterByColumnsMode="Custom" Margin="10,0" >
                <dxe:SearchControl.ColumnProvider>
                    <dxe:SelectorEditColumnProvider>
                        <dxe:SelectorEditColumnProvider.CustomColumns>
                            <sys:String>CODICE</sys:String>
                            <sys:String>NOME</sys:String>
                        </dxe:SelectorEditColumnProvider.CustomColumns>
                    </dxe:SelectorEditColumnProvider>
                </dxe:SearchControl.ColumnProvider>
            </dxe:SearchControl>
            <DockPanel Grid.Row="1" Margin="0,60,0,0">
                <dxg:GridControl x:Name="lst1" ItemsSource="{Binding ListaImpianti}"  EnableSmartColumnsGeneration="True" 
                    FilterCriteria="{Binding FilterCriteria, ElementName=searchControl}"  MaxHeight="500" Height="266" 
                                 VerticalAlignment="Top" Margin="0,-27,0,0" ShowBorder="False" SelectedItem="{Binding SelectedTabImpianti}">
                    <dxg:GridControl.Columns>
                        <dxg:GridColumn x:Name="CODICE" Binding="{Binding CODICE}" FieldName="{DynamicResource ResourceKey=Codice}"/>
                        <dxg:GridColumn x:Name="NOME" Binding="{Binding NOME}" FieldName="{DynamicResource ResourceKey=Nome}"/>
                    </dxg:GridControl.Columns>
                    <dxg:GridControl.View>
                        <dxg:TableView AllowPerPixelScrolling="True" AllowEditing="False" ShowGroupPanel="False" ShowFilterPanelMode="Never"  />
                    </dxg:GridControl.View>
                </dxg:GridControl>
            </DockPanel>
        </Grid>
        <dxlc:LayoutControl Grid.Column="1" Orientation="Vertical" UseLayoutRounding="True" DataContext="{Binding SelectedItem, ElementName=lst1}" Margin="0,10,0,0">
            <dxlc:LayoutGroup Header="{DynamicResource ResourceKey=infogen}" View="GroupBox" Orientation="Vertical" 
                    IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window},Path=DataContext.canEditImpianti}" >
                <dxlc:LayoutItem Label="{DynamicResource ResourceKey=Codice}">
                    <dxe:TextEdit EditValue="{Binding CODICE, UpdateSourceTrigger=PropertyChanged}" MaxLength="10" MaskType="RegEx" Mask="[0-9A-Za-z]{1,10}" 
                                  NullText="{DynamicResource ResourceKey=obbligatorio}" />
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="{DynamicResource ResourceKey=Descrizione}">
                    <dxe:TextEdit EditValue="{Binding NOME, UpdateSourceTrigger=PropertyChanged}" MaxLength="20" MaskType="RegEx" Mask="[0-9A-Za-z ]{1,20}" 
                                  NullText="{DynamicResource ResourceKey=obbligatorio}"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="{DynamicResource ResourceKey=Citta}">
                    <dxe:TextEdit EditValue="{Binding LOCALITA, UpdateSourceTrigger=PropertyChanged}" MaxLength="30"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="{DynamicResource ResourceKey=Indirizzo}">
                    <dxe:TextEdit EditValue="{Binding INDIRIZZO, UpdateSourceTrigger=PropertyChanged}" MaxLength="30"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="{DynamicResource ResourceKey=CAP}">
                    <dxe:TextEdit EditValue="{Binding CAP, UpdateSourceTrigger=PropertyChanged}" MaskType="RegEx" Mask="[0-9]{5}"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="{DynamicResource ResourceKey=IVA}">
                    <dxe:TextEdit EditValue="{Binding PIVA, UpdateSourceTrigger=PropertyChanged}" MaxLength="16"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="{DynamicResource ResourceKey=Telefono}">
                    <dxe:TextEdit EditValue="{Binding TELEFONO, UpdateSourceTrigger=PropertyChanged}" MaskType="Numeric" MaxLength="18"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="{DynamicResource ResourceKey=Responsabile}">
                    <dxe:TextEdit EditValue="{Binding RESPONSABILE, UpdateSourceTrigger=PropertyChanged}" MaxLength="20"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="E-Mail">
                    <dxe:TextEdit EditValue="{Binding EMAILS, UpdateSourceTrigger=PropertyChanged}"
                                  MaskType="RegEx" Mask="[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+'.[A-Za-z]{2,4}"/>
                </dxlc:LayoutItem>
            </dxlc:LayoutGroup>
            <dxlc:LayoutGroup Header="{DynamicResource ResourceKey=ConfTecnica}" View="GroupBox" Orientation="Vertical"
                              IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window},Path=DataContext.canEditImpianti}" >
                <dxlc:LayoutItem Label="{DynamicResource ResourceKey=TipoSistema}">
                    <dxe:ComboBoxEdit IsTextEditable="False" EditValue="{Binding IDTTS, UpdateSourceTrigger=PropertyChanged}" 
                                      ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window},Path=DataContext.tts}"  />
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="{DynamicResource ResourceKey=Locazione}">
                    <StackPanel Margin="0" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left">
                        <RadioButton Content="{DynamicResource Locale}" Margin="10,0,0,0" x:Name="rd_LOCALE" VerticalAlignment="Center"  
                                     IsChecked="{Binding REMOTO,  UpdateSourceTrigger=PropertyChanged,Converter={StaticResource InverseBooleanConverter}}" GroupName="LocationL" Panel.ZIndex="9" TabIndex="10" />
                        <RadioButton Content="{DynamicResource Remoto}" Margin="10,0,6,0" x:Name="rd_REMOTO" VerticalAlignment="Center" 
                                     IsChecked="{Binding REMOTO}" GroupName="LocationR" Panel.ZIndex="10" TabIndex="11" Tag="PRISMA"/>
                    </StackPanel>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="{DynamicResource ResourceKey=TipoConnessione}">
                    <StackPanel Margin="0" Orientation="Horizontal" VerticalAlignment="Center">
                        <RadioButton x:Name="rd_TIPOCONN" Content="{DynamicResource Terminale}" Margin="10,0,0,0" Tag="PRISMA" VerticalAlignment="Center" GroupName="TipoConnT" 
                                     IsChecked="{Binding TIPOCONN, Converter={StaticResource InverseBooleanConverter}, UpdateSourceTrigger=PropertyChanged}" Panel.ZIndex="11" TabIndex="12" />
                        <RadioButton x:Name="rd_SLAVE" Content="Slave" Margin="10,0,6,0" Tag="PRISMA" VerticalAlignment="Center" GroupName="TipoConnS" 
                                     IsChecked="{Binding TIPOCONN}" Panel.ZIndex="12" TabIndex="13" />
                    </StackPanel>
                </dxlc:LayoutItem>
            </dxlc:LayoutGroup>
            <dxlc:LayoutGroup Header="{DynamicResource ResourceKey=CentralinaSTK}" View="GroupBox" Orientation="Vertical"
                              IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window},Path=DataContext.canEditImpianti}" >
                <dxlc:LayoutItem >
                    <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,6">
                        <RadioButton x:Name="rd_sermatic" Content="{DynamicResource SI}" Margin="10,0,0,0"  Tag="PRISMA" VerticalAlignment="Center" Width="100" 
                                     HorizontalAlignment="Left" IsChecked="{Binding SERMATIC, UpdateSourceTrigger=PropertyChanged}" GroupName="stkS" Panel.ZIndex="13" TabIndex="14" />
                        <RadioButton x:Name="rd_sermaticNO" Content="{DynamicResource NO}" Margin="10,0,0,0" Tag="PRISMA" VerticalAlignment="Center" Width="100" 
                                     HorizontalAlignment="Left" IsChecked="{Binding SERMATIC, Converter={StaticResource InverseBooleanConverter}, UpdateSourceTrigger=PropertyChanged}" GroupName="stkN" 
                                     Panel.ZIndex="14" TabIndex="15" />
                    </StackPanel>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem >
                    <!--<dxe:ComboBoxEdit  EditValue="{Binding SERMATICCOM}"/>-->
                    <UniformGrid Rows="1" Columns="2" DockPanel.Dock="Top" Margin="4,0,4,4" IsEnabled="{Binding IsChecked, ElementName=rd_sermatic, UpdateSourceTrigger=PropertyChanged}">
                        <TextBlock Margin="0" TextWrapping="Wrap" Text="{DynamicResource PortaCOM}" TextAlignment="Right" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                        <dxe:ComboBoxEdit IsTextEditable="False" EditValue="{Binding SERMATICCOM, UpdateSourceTrigger=PropertyChanged}" >
                            <dxe:ComboBoxEdit.Items>
                                <dxe:ComboBoxEditItem Content="COM1"/>
                                <dxe:ComboBoxEditItem Content="COM2"/>
                                <dxe:ComboBoxEditItem Content="COM3"/>
                                <dxe:ComboBoxEditItem Content="COM4"/>
                                <dxe:ComboBoxEditItem Content="COM5"/>
                                <dxe:ComboBoxEditItem Content="COM6"/>
                                <dxe:ComboBoxEditItem Content="COM7"/>
                                <dxe:ComboBoxEditItem Content="COM8"/>
                            </dxe:ComboBoxEdit.Items>
                        </dxe:ComboBoxEdit>
                    </UniformGrid>
                </dxlc:LayoutItem>
            </dxlc:LayoutGroup>
        </dxlc:LayoutControl>
    </Grid>
</ScrollViewer>

XAML:禁用容器中的所有元素,但滚动

我只是禁用了内部布局组。它有效。