Skip to content

Commit 3639688

Browse files
committed
#102: Add sample to show that converters don't work as expected
1 parent 6d3e9b9 commit 3639688

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/BasicSample/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
</DataTemplate>
3232
</DataGridTemplateColumn.CellEditingTemplate>
3333
</DataGridTemplateColumn>
34+
<DataGridTextColumn Header="Converter can't work" Binding="{Binding Index, Converter={basicSample:ModuloConverter}}" />
3435
</DataGrid.Columns>
3536
</DataGrid>
3637
</Grid>

src/BasicSample/ModuloConverter.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace BasicSample
2+
{
3+
using System;
4+
using System.Globalization;
5+
using System.Windows.Data;using System.Windows.Markup;
6+
7+
public class ModuloConverter : MarkupExtension, IValueConverter
8+
{
9+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10+
{
11+
if (value is not int index)
12+
return null;
13+
14+
return $"{index % 10}: {value}";
15+
}
16+
17+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
22+
public override object ProvideValue(IServiceProvider serviceProvider)
23+
{
24+
return this;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)