91

好的,发现System.Windows.Controls命名空间中已经有一个BooleanToVisibilityConverter真是一个惊喜(在多次编写之后)。

可能还有更多这样隐藏的节省时间的方法。

有人有吗?

4

2 回答 2

104

I did a quick trawl using the Object Browser and this is what I have.

Derived from IValueConverter:

System.Windows.Controls.AlternationConverter
System.Windows.Controls.BooleanToVisibilityConverter
System.Windows.Documents.ZoomPercentageConverter
System.Windows.Navigation.JournalEntryListConverter

Xceed.Wpf.DataGrid.Converters.CurrencyConverter
Xceed.Wpf.DataGrid.Converters.DateTimeToStringConverter
Xceed.Wpf.DataGrid.Converters.GreaterThanZeroConverter
Xceed.Wpf.DataGrid.Converters.IndexToOddConverter
Xceed.Wpf.DataGrid.Converters.IntAdditionConverter
Xceed.Wpf.DataGrid.Converters.InverseBooleanConverter
Xceed.Wpf.DataGrid.Converters.LevelToOpacityConverter
Xceed.Wpf.DataGrid.Converters.MultimodalResultConverter
Xceed.Wpf.DataGrid.Converters.NegativeDoubleConverter
Xceed.Wpf.DataGrid.Converters.NullToBooleanConverter
Xceed.Wpf.DataGrid.Converters.SourceDataConverter
Xceed.Wpf.DataGrid.Converters.StringFormatConverter
Xceed.Wpf.DataGrid.Converters.ThicknessConverter
Xceed.Wpf.DataGrid.Converters.TypeToBooleanConverter
Xceed.Wpf.DataGrid.Converters.TypeToVisibilityConverter
Xceed.Wpf.DataGrid.Converters.ValueToMaskedTextConverter

Derived from IMultiValueConverter:

System.Windows.Controls.BorderGapMaskConverter
System.Windows.Navigation.JournalEntryUnifiedViewConverter
System.Windows.Controls.MenuScrollingVisibilityConverter

Microsoft.Windows.Themes.ProgressBarBrushConverter
Microsoft.Windows.Themes.ProgressBarHighlightConverter

Note the Xceed ones (no connection) are available free with their DataGrid. As well as those there's some clever stuff around like the debugging converter. I've also used the last IValueConverter and I'm sure there's some further lambda function goodness to be found, too.

于 2009-02-03T02:09:47.853 回答
29

在 3.5 SP1 之前,字符串格式化需要 IValueConverter。现在,您可以使用 Binding 上的StringFormat属性来执行此操作。

从 MSDN 页面:

<DataTemplate>
  <TextBlock>
    <TextBlock.Text>
      <MultiBinding  StringFormat="{}{0} -- Now only {1:C}!">
        <Binding Path="Description"/>
        <Binding Path="Price"/>
      </MultiBinding>
    </TextBlock.Text>
  </TextBlock>
</DataTemplate>
于 2009-02-02T23:42:34.187 回答