我有这个漂亮的小窗户。
w
我希望此DataGrid关闭我的大小调整和重新排序功能,我希望无法编辑单元格。但是,这是行不通的。.我希望当我单击行时仍能选择并突出显示行。由于某些原因,这不起作用...
MVCE:即使在该行上选择行也不起作用
<Window x:Class="Kassa.OfficeMainWindow"
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:Kassa"
mc:Ignorable="d"
Title="Kontor" Height="720" Width="1280" WindowStartupLocation="CenterOwner">
<TabControl SelectionChanged="TabControl_SelectionChanged">
<TabItem Header="Müük">
<TabControl>
<TabItem Header="Ülevaade"></TabItem>
<TabItem Header="Sooduskampaaniad"></TabItem>
</TabControl>
</TabItem>
<TabItem Header="Kliendid"></TabItem>
<TabItem Header="Tootehaldus ja ladu" x:Name="ProductsTab">
<DockPanel>
<GroupBox Header="Otsi tootekoodi, triipkoodi või nime järgi, või lisa uus toode" Padding="0,4,0,0" DockPanel.Dock="Top">
<Grid Height="22">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" x:Name="ProductSearchBox" KeyUp="ProductSearchBox_KeyUp" VerticalContentAlignment="Center"></TextBox>
<Button Grid.Column="2" Padding="8,0" Margin="8,0">Uus toode</Button>
</Grid>
</GroupBox>
<GroupBox Header="Tulemuste filtreerimine ja lao operatsioonid" Padding="0,4,0,0" DockPanel.Dock="Top">
<DockPanel>
<StackPanel DockPanel.Dock="Left" Orientation="Horizontal">
<CheckBox VerticalContentAlignment="Center" Padding="4,0" IsChecked="True" x:Name="CheckBoxAllProducts" Click="CheckBoxForProducts_Click">Kõik</CheckBox>
<CheckBox VerticalContentAlignment="Center" Padding="4,0" x:Name="CheckBoxProductsInStock" Click="CheckBoxForProducts_Click">Laos</CheckBox>
<CheckBox VerticalContentAlignment="Center" Padding="4,0" x:Name="CheckBoxProductsBelowCritical" Click="CheckBoxForProducts_Click">Allpool kriitilist kogust</CheckBox>
<CheckBox VerticalContentAlignment="Center" Padding="4,0" x:Name="CheckBoxProductsOutOfStock" Click="CheckBoxForProducts_Click">Laost otsas</CheckBox>
<CheckBox VerticalContentAlignment="Center" Padding="4,0" x:Name="CheckBoxNotInventoried" Click="CheckBoxForProducts_Click">Laoseisu ei arvestata</CheckBox>
<CheckBox VerticalContentAlignment="Center" Padding="4,0" x:Name="CheckBoxArchieved" Click="CheckBoxForProducts_Click">Arhiveeritud</CheckBox>
</StackPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right" HorizontalAlignment="Right">
<Button Padding="8,0" Margin="8,0" Height="22">Lattu võtmine</Button>
</StackPanel>
</DockPanel>
</GroupBox>
<DataGrid DockPanel.Dock="Bottom" x:Name="ProductDataGrid" HorizontalGridLinesBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" SelectionUnit="FullRow" VerticalGridLinesBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserResizeRows="False" IsReadOnly="True" RowHeaderWidth="0">
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsCritical}" Value="True">
<Setter Property="Foreground" Value="Red"></Setter>
</DataTrigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Blue" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Tootekood" Width="*" Binding="{Binding Path=Code}"></DataGridTextColumn>
<DataGridTextColumn Header="Nimetus" Width="*" Binding="{Binding Path=Name}"></DataGridTextColumn>
<DataGridTextColumn Header="Triipkood" Width="*" Binding="{Binding Path=Barcode}"></DataGridTextColumn>
<DataGridTextColumn Header="Laoseisuga" Binding="{Binding Path=HasInventory}"></DataGridTextColumn>
<DataGridTextColumn Header="Laos ühikuid" Binding="{Binding Path=CurrentStock}">
<DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsTracked}" Value="False">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"></Setter>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Kriitiline kogus" Binding="{Binding Path=CriticalStock}">
<DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsTracked}" Value="False">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"></Setter>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Omahind" Binding="{Binding Path=SelfPrice}"></DataGridTextColumn>
<DataGridTextColumn Header="KM %" Binding="{Binding Path=VATPercentage}"></DataGridTextColumn>
<DataGridTextColumn Header="Müügihind" IsReadOnly="True" Binding="{Binding Path=SellingPrice}"></DataGridTextColumn>
<DataGridTextColumn Header="Staatus" Binding="{Binding Path=Status}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</TabItem>
</TabControl>
</Window>
答案 0 :(得分:0)
这是错误的地方,错误是我在<TabControl SelectionChanged="TabControl_SelectionChanged">
SelectionChanged中所做的,正在设置数据网格内容。事实证明,每当您在选项卡中选择控件时,该事件都会冒泡至TabControl,因此该行不会被选中。