如何获取DataGridColumn的转换器

时间:2014-09-09 07:15:00

标签: wpf xaml wpfdatagrid

我需要获取DataGridColumn的转换器。 这是DataGrid和Column' NoteType' XAML:

<DataGrid x:Name="grdConsolidatedNotes"
          Grid.Row="3"
          HorizontalAlignment="Stretch"
          VerticalAlignment="Stretch"
          AutoGenerateColumns="False"
          BorderBrush="Transparent"
          CanUserAddRows="False"
          ColumnWidth="*"
          HorizontalScrollBarVisibility="Auto"
          ItemsSource="{Binding Path=ConsolidatedNotes}"
          LostFocus="GrdConsolidatedNotes_OnLostFocus"
          Padding="0"
          ScrollViewer.CanContentScroll="False"
          SelectionMode="Single"
          SelectionUnit="FullRow"

          VerticalScrollBarVisibility="Auto"
          Visibility="{Binding Path=DataGridVisibility,
                               Mode=OneWay}"
          Sorting="GrdConsolidatedNotes_OnSorting">
            <DataGridTemplateColumn Width="Auto"
                                CellTemplate="{StaticResource CNNoteTypeCellTemplate}"
                                Header="{Binding hdrType,
                                                 Source={StaticResource ResourceString}}"
                                SortMemberPath="NoteType" />

这是CellTemplate的XAML&CNNoteTypeCellTemplate&#39;上面使用的:

   <DataTemplate x:Key="CNNoteTypeCellTemplate">
        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="8" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="8" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="8" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="8" />
            </Grid.ColumnDefinitions>

            <TextBlock x:Name="NoteTypeTextBlock"
                       Grid.Column="1"
                       MinHeight="20"
                       Margin="0,5,5,0"
                       HorizontalAlignment="Stretch"
                       VerticalAlignment="Center"
                       Text="{Binding Path=NoteType,
                                      Converter={StaticResource noteTypeTextConverter}}" />
        </Grid>
    </DataTemplate>

我需要检索转换器&#34; noteTypeTextConverter&#34;在代码隐藏中使用上面的代码。 请建议。

1 个答案:

答案 0 :(得分:0)

试试this.FindResource(“noteTypeTextConverter”); 这是添加noteTypeTextConverter的地方。