1. 以下是绑定方式,但是IsReadOnly不起作用

<DataGrid x:Name="dgTest" ItemsSource="{Binding}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Header="Name" IsReadOnly="{Binding Path=Pass}" Binding="{Binding Path= Name}"/>
</DataGrid.Columns>
<DataGrid>

2. IsReadOnly不是针对某个cell的约定,而是对整列起作用,所以这样的绑定有问题。

3. 可以替换成以下代码:

DataGridTextColumn 换为 DataGridTemplateColumn 
<DataGridTemplateColumn Header="Name">
          <DataGridTemplateColumn.CellTemplate>
                   <DataTemplate>
                            <TextBlock Text="{Binding Path=Name,Mode=OneWay}" />
                   </DataTemplate>
           </DataGridTemplateColumn.CellTemplate>
           <DataGridTemplateColumn.CellEditingTemplate>
                   <DataTemplate>
                            <TextBox Text="{Binding Path=Name,Mode=TwoWay}" IsReadOnly="{Binding Path=Pass}"/>
                  </DataTemplate>
            </DataGridTemplateColumn.CellEditingTemplate>
 </DataGridTemplateColumn>

4. 双击进入编辑界面的时候TextBox没有默认聚焦鼠标光标。修改如下:

FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}"
      <DataTemplate x:Key="cellEditingTemplate">
<local:MultiLineTextBox x:Name="multiLineTxt" Text="{Binding Description}"/>
<DataTemplate.Triggers>
<Trigger SourceName="multiLineTxt" Property="IsVisible" Value="True">
<Setter TargetName="multiLineTxt" Property="FocusManager.FocusedElement" Value="{Binding ElementName=multiLineTxt}"/>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>

OR

<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<StackPanel>
<TextBox x:Name="editCommentTextBox" Text="{Binding Comment, Mode=TwoWay}"
FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}">
</TextBox>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>

5.cell添加背景颜色CellStyle="{StaticResource  dgCellStyle}"

       <Style x:Key="dgCellStyle"  TargetType="DataGridCell">
<Setter Property="Background" Value="#DDFFDE"/>
</Style>

6. 根据是否只读决定单元格的北京颜色

            <DataGridTemplateColumn.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsReadOnly}" Value="False">
<Setter Property="Background" Value="#DDFFDE"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTemplateColumn.CellStyle>

参考:

http://www.cnblogs.com/fwbnet/archive/2012/05/08/2490974.html

http://www.cnblogs.com/zhcw/archive/2013/01/12/2857433.html

关于 DataGridTextColumn的IsReadOnly的更多相关文章

  1. WPF DataGrid自定义列DataGridTextColumn.ElementStyle和DataGridTemplateColumn.CellTemplate

    <Window x:Class="DataGridExam.MainWindow"        xmlns="http://schemas.microsoft.c ...

  2. 【转】WPF 给DataGridTextColumn统一加上ToolTip

    源地址:http://dongguojun.iteye.com/blog/1671963 我发现WPF中DataGridTextColumn直接设置它的ToolTipService.Tooltip并不 ...

  3. The tag 'DataGridTextColumn' does not exist in XML namespace ....

    错误 10 The tag 'DataGridTextColumn' does not exist in XML namespace 'http://schemas.microsoft.com/win ...

  4. 由DataGridTextColumn不能获取到父级DataContext引发的思考

    在项目中使用DataGrid需要根据业务动态隐藏某些列,思路都是给DataGrid中列的Visibility属性绑定值来实现(项目使用MVVM),如下 <DataGridTextColumn H ...

  5. 使用NPOI导出Excel引发异常(IsReadOnly = “book.IsReadOnly”引发了类型“System.NotImplementedException”的异常)

    前言: 本人调式npoi导入.导出试用成功后,引入到项目中,导入完美运行,但是导出怎么样都看不到现在的页面,而且浏览器和后台都没有报任务错误,让人好事纳闷,后来去调式,发现在除了一个IsReadOnl ...

  6. C#服务器控件 IsReadOnly 和 Visibility,IsEnable 的区别

    IsReadOnly  适用于“输入.输出”类控件,比如TextBox类, 可以当做文本输入,也可以通过后台代码进行输出. 设置 IsReadOnly(只读) = true 后,该控件只允许输出,不允 ...

  7. 2018-8-10-wpf-绑定-DataGridTextColumn-

    title author date CreateTime categories wpf 绑定 DataGridTextColumn lindexi 2018-08-10 19:16:53 +0800 ...

  8. DataGrid DataGridTextColumn 樣式

    <DataGridTextColumn.ElementStyle> <Style TargetType="TextBlock" > <Setter P ...

  9. WPF DataGrid DataGridTextColumn

    Style设置时,无法绑定到数据,需要这样写 1 <DataGridTextColumn Header="呵呵" Binding="{Binding ID}&quo ...

随机推荐

  1. WebBrowser的Cookie操作之流量刷新机

    最近一直在思考着如何通过代码去伪装或实现人工自然浏览网页的效果,起初能想到的是用WebBrowser实现这一效果,需要达到的功能预想有以下几点: 1.自动刷新 2.模拟人工下拉滚动条并停留一段时间: ...

  2. .NET轻量级RPC框架:Rabbit.Rpc

    最近准备写一个.NET的管理平台应用在公司,由于存在大量的Client => Server,Server => Client的请求需求在加上之前一直接触了解过RpcClient组件的开发, ...

  3. ORACLE 9i 数据库体系结构图

    ORACLE 9i 的数据库体系结构图,非常的全面.系统.高屋建瓴的整体介绍了ORACLE 9i 的数据库体系结构.如果能全面了解.清晰梳理.深入掌握这些知识点,相信对你了解学习.深入研究ORACLE ...

  4. JQuery.Ajax之错误调试帮助信息

    下面是Jquery中AJAX参数详细列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求 ...

  5. 不好的MySQL过程编写习惯

    刚才为了测试一个东西,写了个存储过程: delimiter $$ drop procedure if exists sp_test$$ create procedure sp_test() begin ...

  6. 使用valgrind检查内存

    Valgrind是运行在Linux上一套基于仿真技术的程序调试和分析工具,是公认的最接近Purify的产品,它包含一个内核——一个软件合成的CPU,和一系列的小工具,每个工具都可以完成一项任务——调试 ...

  7. 使用WinRar软件制作程序安装包

    之前我写过使用好压软件打包程序,见随笔: 使用好压(HaoZip)软件打包EverEdit制作安装程序 - Fetty - 博客园http://www.cnblogs.com/fetty/p/4907 ...

  8. [WPF系列]-DynamicResource与StaticResource的区别

    探讨: 1.当引用资源时,选择StaticResource还是DynamicResource的考虑因素: (1)在哪里创建资源?(资源的范围或层级) a. 资源是在一个Page/Canvas/Wind ...

  9. Java程序生成exe可执行文件详细教程(图文说明)

    ava程序打包成exe可执行文件,分为两大步骤. 第一步:将Java程序通过Eclipse或者Myeclipse导成Jar包 第二步:通过exe4j讲Jar包程序生成exe可执行文件 第一步详解: 将 ...

  10. POJ2001Shortest Prefixes[Trie]

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17683   Accepted: 768 ...