在我的节目,我有一个包含一个用户控件DataGrid是有它的ItemsSource必然的ObservableCollection。为此,DataGrid我需要能够禁用和灰显特定的单元格。我想最好在 c++ 中执行此操作,因为我可能需要更改在运行时发生的单元格。我知道如何使用IsReadOnly,但似乎我只能为整个列切换它。这成为一个问题,因为我的列绑定到数据,这使我更难定位特定的网格单元格。
话虽如此,
XAML:
<DataGrid ItemsSource="{Binding Model.Collection}" ... >
<DataGrid.Columns>
<!-- Row Number -->
<DataGridTextColumn Width="SizeToCells" IsReadOnly="True" Binding="{Binding rowNum}" />
<!-- Inputs -->
<DataGridTextColumn Width="SizeToCells" IsReadOnly="False" Header="Inputs" Binding="{Binding input}" />
<!-- Outputs -->
<DataGridTextColumn Width="SizeToCells" IsReadOnly="False" Header="Outputs" Binding="{Binding output}" />
</DataGrid.Columns>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
数据模型:
namespace Program.Data_Models
{
public class CartIO_Model : PropertyChangedBase
{
private string test1 = "One";
private string test2 = "Two";
private string test3 = "Three";
private string …Run Code Online (Sandbox Code Playgroud)