2012-05-17 76 views
0

我有datagrid單元格,並在其下有一個文本框控件。如何使用路由事件調用文本框控件的文本更改事件? 我試過EventSetter,但它不工作。WPF數據網格單元格文本框控件

這裏是代碼:

<Style TargetType="{x:Type DataGridCell}" x:Key="DatagridCellWithTextbox"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type DataGridCell}"> 
       <Grid Background="{TemplateBinding Background}"> 
        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"> 
         <TextBox x:Name="txtCell" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.Text}" VerticalContentAlignment="Top" TextChanged="">         
         </TextBox> 
        </Border> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
    </Style> 

感謝 迪

+1

你能否提供答案爲什麼你給-1票。 – Dee

+0

可能是因爲您再次提出幾乎相同的問題。 – LPL

+1

請提供給我鏈接,我已經問過這種情況的問題。 – Dee

回答

0

我測試過

<TextBox x:Name="txtCell" TextChanged="txtCell_TextChanged"> 

,它是工作。你給你的風格x:Key。你應用了這種風格嗎?

<DataGrid.Columns> 
    <DataGridTemplateColumn CellStyle="{StaticResource DatagridCellWithTextbox}" /> 
</DataGrid.Columns>