2014-08-28 35 views
0

我嘗試獲取單元格內容作爲類,例如我綁定 我該怎麼做?DataGridCell獲取綁定值

<Style TargetType="{x:Type DataGridCell}"> 
        <Style.Triggers > 
         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Content, Converter={StaticResource MyConverter}}" Value="1"> 
          <Setter Property="Margin" Value="15,0,0,0" /> 
         </DataTrigger> 
</Style.Triggers> 
</Style> 

這裏是轉換器類:

public class MyConverter : IValueConverter 
    { 
     public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
     { 
      if (value!= null) 
      { 
       //to do value is TextBlcock and I cant get value need I 
      } 
      return value; 
     } 
    } 
+0

我不明白你正在嘗試做的(你的問題不清楚),你找'值TextBlcock'? – Sayse 2014-08-28 13:44:21

+0

我綁定一個DataTable它包含一個Colums到網格,如 dcolumn = new DataColumn(「colname」); dcolumn.Caption =「colname Caption」; dcolumn.DataType = typeof(MyClass); this.Data.Columns.Add(dcolumn); 我嘗試在轉換器中獲取MyClass數據 – 2014-08-28 13:54:05

回答

0

我找到一個解決方案here。最好的解決辦法似乎是

DataGridRow發送到轉換器

<MultiBinding Converter="{StaticResource MyConverter}" Mode="OneWay"> 
            <Binding Path="." RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGridRow}" /> 
            <Binding Path="." RelativeSource="{RelativeSource Self}"/> 
           </MultiBinding>