当silverlight DataGrid中的行高减少时,键入的字符不可见

时间:2014-04-01 05:26:43

标签: silverlight datagrid

我有一个silverlight数据网格,其行高和字体要减少,因为要在其中显示更多行而不增加总高度。

我已将row height设置为15,将font size设置为10。它的所有内容都清晰可见,但是当我在其中一个单元格中键入一些文本时,键入的内容在我输入时不可见。当我完成输入文本并按下时,我可以看到它。

当我在其中一个单元格中键入一些文本时,它就是这样的: enter image description here

我该如何解决这个问题?

编辑:.xaml中的相关部分:

 <sdk:DataGrid AutoGenerateColumns="False" Height="171" HorizontalAlignment="Left" Name="StockistClaimDetailsGrid" VerticalAlignment="Top" Width="756" Margin="0,20,0,0" RowHeight="15">
   <sdk:DataGrid.Columns>
     <sdk:DataGridTemplateColumn Header="" Width="30" >
       <sdk:DataGridTemplateColumn.CellTemplate>
         <DataTemplate>
           <CheckBox Height="16" x:Name="CheckBox" Checked="CheckBox_Checked" IsChecked="{Binding IsChecked, Mode=TwoWay}" IsEnabled="{Binding CheckBoxEnabled, Mode=TwoWay}" Tag="{Binding}" />
         </DataTemplate>
       </sdk:DataGridTemplateColumn.CellTemplate>
     </sdk:DataGridTemplateColumn>  

     <sdk:DataGridTextColumn x:Name="Remarks" Binding="{Binding Remarks}" Header="Remarks" IsReadOnly="False" Width="300" FontSize="10" />
   </sdk:DataGrid.Columns>
 </sdk:DataGrid>

1 个答案:

答案 0 :(得分:0)

DataGrid使用两个不同的TextBox个实例来显示单元格的内容并进行编辑。所以我猜文字样式设置已应用于显示TextBox,但未应用于编辑TextBox

那么,如何解决这个问题呢? 我找到了属性EditingElementStyle on msdn。这似乎可以解决问题。 只需指定相同的TextBoxStyle。

<Style x:Key="SmallTextBoxStyle" TargetType="TextBox">
    <Setter Property="FontSize" Value="10"/>
</Style>
...
<sdk:DataGridTextColumn EditingElementStyle="{StaticResource SmallTextBoxStyle}" FontSize="10"/>

[编辑]我刚发现ElementStyle必须适用于TextBlock。所以你不能重复使用Style,但你可以复制样式并相应地设置TaregtType。或者只是省略ElementStyle并在列上设置FontSize,如上所示。

<Style x:Key="SmallTextBlockStyle" TargetType="TextBlock">
    <Setter Property="FontSize" Value="10"/>
</Style>
<Style x:Key="SmallTextBoxStyle" TargetType="TextBox">
    <Setter Property="FontSize" Value="10"/>
</Style>
...
<sdk:DataGridTextColumn
      ElementStyle="{StaticResource SmallTextBlockStyle}"
      EditingElementStyle="{StaticResource SmallTextBoxStyle}"/>