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. [Erlang 0108] Elixir 入门

    Erlang Resources里面关于Elixir的资料越来越多,加上Joe Armstrong的这篇文章,对Elixir的兴趣也越来越浓厚,投入零散时间学习了一下.零零散散,测试代码写了一些,Ev ...

  2. 将String转化成Stream,将Stream转换成String

    using System;using System.IO;using System.Text;namespace CSharpConvertString2Stream{     class Progr ...

  3. -bash: .bash_profile: command not found

    今天有一同事安装了ORACLE后,在切换账号时遇到错误提示"-bash: .bash_profile: command not found".如下所示 [root@GLETestL ...

  4. SQL Server自动化运维系列——监控跑批Job运行状态(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在上一篇文章中已经分析了SQL SERVER中关于邮 ...

  5. sql server 2012 数据引擎任务调度算法解析(上)

    微软在sql server 2012版本之后,引入了新的任务调度算法,这个算法与之前的版本有一些细微的差别.我在这里试着简单描述一下,一些基本概念就不再赘述了,比如NUMA.scheduler.wor ...

  6. 烂泥:openvpn配置文件详解

    本文由秀依林枫提供友情赞助,首发于烂泥行天下 在上一篇文章<烂泥:ubuntu 14.04搭建OpenVPN服务器>中,我们主要讲解了openvpn的搭建与使用,这篇文章我们来详细介绍下有 ...

  7. Vsphere初试——基本安装

    现有工具: 一台Dell PowerEdge R820服务器 VMware-VMvisor-Installer-5.5.0.update01-1623387.x86_64(ESXi).iso VMwa ...

  8. spring中的定时调度实现TimerFactoryBean引起的隐患

    手中的一个老项目,其中使用的TimerFactoryBean实现的调度任务.一般都是spring quartz实现,这种的着实少见.正因为少见资料比较少,当初为了确认这个会不会2个调度任务同时并行执行 ...

  9. Xamarin.Android VSTS 持续集成

    这些天做了一个基于 VSTS 的 Xamarin.Android的持续集成,这里分享下 Build Agent 环境需求 DotNetFramework msbuild visualstudio An ...

  10. [转]17个新手常见Python运行时错误

    原址:http://www.oschina.net/question/89964_62779?p=1 当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的 ...