2009-07-22 74 views
1

我希望能夠爲DataGridTextColumn的某些屬性(即寬度,排序順序等)添加綁定,但是看起來這些屬性不是DependencyPropertys,所以他們不能被束縛。另一個答案建議子類DataGridTextColumn作爲DependencyPropertys公開這些屬性,但我似乎無法找到任何信息如何做到這一點。Silverlight:在DependencyProperty中包裝非DependencyProperty

感謝, 羅伯特

回答

0

在Silverlight中,只有FrameworkElement(不DependencyObject)子類可以有DependencyProperty秒。所以不可能直接綁定到DataGridColumn的屬性。

0

試試這個:

public class BindableGridColumn : DataGridTextColumn 
    { 
     public DataGridLength BindableWidth 
     { 
      get { return Width; } 
      set { 
        SetValue(BindableWidthProperty, value); 
        Width = value; 
       } 
     } 

     // Using a DependencyProperty as the backing store for BindableWidth. This enables animation, styling, binding, etc... 
     public static readonly DependencyProperty BindableWidthProperty = 
      DependencyProperty.Register("BindableWidth", typeof(DataGridLength), typeof(BindableGridColumn), new PropertyMetadata(DataGridLength.Auto)); 
    } 
+0

呃...它不起作用,因爲當它通過綁定設置時,不會調用任何回調,並且通過該屬性設置時,DependancyProperty不會更改。 – 2009-07-22 21:50:59

+1

對不起,我一定爲時過早嘗試!是的,我可以看到設置綁定的BindableWidth不會改變DP。在屬性設置器中添加了對SetValue的調用。另一種方式是行不通的,即如果直接設置寬度屬性,BindableWidth將不會更新,但我認爲這不適用於這種情況。 – 2009-07-23 12:22:01

+0

謝謝!但無論如何,因爲DataGridColumn不是FrameworkElement,所以它不能被綁定。 – 2009-07-24 21:02:07

相關問題