2017-05-21 6 views
0

이 DataGridCell이 있고이 변환기를 호출합니다. 나는이 셀의 값이 "hi"(셀 "content"를 "hi"로 설정하고 있음)를 기대하고 있었는데, 컨버터를 통과 한 후에 DataGrid에 표시되었을 때였습니다.C# wpf DataGridCell에서 값을 설정하십시오.

내가 뭘 잘못하고 있니?

<DataGridTextColumn Width="60" Header="Google" CanUserResize="True" CanUserSort="True"> 
    <DataGridTextColumn.HeaderStyle> 
     <Style TargetType="{x:Type DataGridColumnHeader}"> 
      <Setter Property="ToolTip" Value="Current Position on Google" /> 
      <Setter Property="HorizontalContentAlignment" Value="Center"/> 
     </Style> 
    </DataGridTextColumn.HeaderStyle> 
    <DataGridTextColumn.CellStyle> 
     <Style TargetType="{x:Type DataGridCell}"> 
      <Setter Property="HorizontalAlignment" Value="Center"/> 
      <Setter Property="FontSize" Value="12"/> 
      <Setter Property="VerticalAlignment" Value="Center"/> 
      <EventSetter Event="MouseUp" Handler="IdUnselect"/> 

      <Setter Property="Background" Value="{Binding GoogleKeywordPositionMovementSinceLastWeekCheck, Converter={StaticResource NameToBrushConverter}}"/> 
      <Setter Property="Content"  Value="{Binding Path=., Converter={StaticResource GooglePositionConvertor}}"/> 

     </Style> 
    </DataGridTextColumn.CellStyle> 

</DataGridTextColumn> 



public class GooglePositionConvertor : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     ResultCheckObject RankCheck = value as ResultCheckObject; 

     return "hi"; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 
+0

당신은 바인딩을 열심히하지만, 현재 소스는 무엇인가!? 그리고 변환기에서 ResultCheckObject에 값을 던져 넣지 만 '안녕'을 반환하면 왜 그 값을 사용하지 않을까요? –

+0

변환기를 통해 DataGrid 셀의 내용/텍스트를 어떻게 설정합니까? – jamie

+0

예를 들어 데이터 컨텍스트에 바인딩 할 속성 int가있을 수 있습니다. 그러면 해당 속성 값이 변환기를 거쳐 다시 돌아옵니다. –

답변

0

아래의 방법으로 변환기를 통해 내용을 설정하지 못했습니다. 아래와 같이 변환기를 통해 설정

<Setter Property="Content" Value="{Binding Path=., Converter={StaticResource GooglePositionConvertor}}"/> 

는. = 현재의 소스 경로에

<DataGridTextColumn Width="60" Header="Google" Binding="{Binding Path=., Converter={StaticResource GooglePositionConvertor}}" CanUserResize="True" CanUserSort="True">