我面臨一個我認爲會很容易解決的問題,但是......結果並不那麼容易。DataGrid:Dynamic StringFormat
這就是情況:我創建了一個定製UserControl
,它繼承自WPFToolkit的DataGrid
(我需要在.NET 3.5中工作:/)。
此控件是一個顯示財務值的矩陣,用戶應該能夠選擇顯示格式(百分比,絕對值,1或2位小數的百分比......)。
而......也許我只是在這裏愚蠢,但我無法解決它。 我的控件有一個自定義DependencyProperty
,其中包含完整的市場數據參考,然後將參考的特定部分分配給特定屬性(例如,價格差異將轉至ItemsSource
)。 由於用戶可以更改顯示內容(價格,價格差異,昨天的價格,其他隨機財務資料...),顯示格式將定期更改,用戶應允許自行選擇。
我的電池只需按照一個Style
定義我ResourceDictionary
:
<Style x:Key="CellStyle" TargetType="{x:Type tk:DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type tk:DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我不會Binding
的StringFormat
事業工作,我不綁定ItemsSource
(我將它後面的代碼當市場參考屬性更改)
我已經看到this answer, proposing a converter
不過,好像我不知道我應該在哪裏添加一個轉換器單元s ...
任何想法?
謝謝!