gpt4 book ai didi

c# - 如何使用mvvm在WPF中的DataGrid中的单元格中进行IsReadOnly更改

转载 作者:行者123 更新时间:2023-12-03 10:22:57 26 4
gpt4 key购买 nike

我的网格如下。

我想要的是,如果选中了datagrid中的复选框,则选中True Holoday Name应该为True,否则应为可编辑。

<DataGrid CanUserDeleteRows="False" CanUserAddRows="False" Name="dgwCalenderDetails" SelectionMode="Single" ItemsSource="{Binding CalenderDetails, Mode=TwoWay}" IsReadOnly="False" AutoGenerateColumns="False" Width="770">
<DataGrid.Columns>
<DataGridTextColumn Header="Day Id" Binding="{Binding DayId}" Visibility="Hidden" IsReadOnly="False" />
<DataGridTextColumn Header="Day" Binding="{Binding DayName}" Width="100" IsReadOnly="False"/>
<DataGridTextColumn Header="Date" Binding="{Binding DisplayDate, StringFormat={}{0:dd/MM/yyyy}}" Width="75" IsReadOnly="False"/>
<DataGridTextColumn Header="Start Time" Binding="{Binding StartTime, StringFormat=N2}" Width="100" IsReadOnly="False"/>
<DataGridTextColumn Header="Working Hours" Binding="{Binding NoOfWorkingHrs, StringFormat=N2}" Width="100" IsReadOnly="False"/>
<DataGridCheckBoxColumn Header="Holiday Status" Binding="{Binding IsHolidayYN}" Width="100" CanUserReorder="False"/>
<DataGridTextColumn Header="Holoday Name" Binding="{Binding HolidayName}" Width="*" IsReadOnly="False" />
</DataGrid.Columns>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Background" Value="White"/>
<Setter Property="IsEnabled" Value="True"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsHolidayYN}" Value="true">
<Setter Property="Background" Value="Gray"/>
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
</DataGrid>

最佳答案

<DataGridTextColumn Binding="{Binding HolidayName}" >
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="IsEnabled" Value="{Binding IsHolidayYN}" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>

关于c# - 如何使用mvvm在WPF中的DataGrid中的单元格中进行IsReadOnly更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26354387/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com