我想对条形码列进行过滤。 在这列中,我有一个转换器来转换字符串中的Eans列表。课程是这样的:
public class EanListToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
return String.Join("\r", ((List<Ean>)value).Select(ean => ean.Codice));
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
return NotSupportedException();
}
private object NotSupportedException()
{
throw new NotImplementedException();
}
}
所以我希望如果用户在 TEXTBOX (或其他)中编写条形码来过滤DataGrid列表。
<DataGrid HorizontalAlignment="Stretch" SelectedItem="{Binding SelectedArticle}"
Margin="14,89,12,61" VerticalAlignment="Stretch" AutoGenerateColumns="False" x:Name="List">
<DataGrid.Columns>
<DataGridTextColumn Width="100" Binding="{Binding Code}" Header="Code" />
<DataGridTextColumn Width="300" Binding="{Binding Description}" Header="Description" />
<DataGridTextColumn Binding="{Binding Price}" Header="Price" />
<DataGridTextColumn Binding="{Binding Ean, Converter={StaticResource EanListToString}}" Header="Bar Codes" />
</DataGrid.Columns>
</DataGrid>
这是视图模型
[Export(typeof(IScreen))]
public class BViewModel : Screen
{
public List<Articolo> List { get; private set; }
public Article SelectedArticle { get; set; }
[Import]
WindowManager WindowManager = new WindowManager();
public BolleViewModel()
{
List = recover.GetArticles();
NotifyOfPropertyChange("List");
}
}
我能做什么?感谢..
答案 0 :(得分:1)
从View开始我建议你首先使用 DataGridTemplateColumn ,特别是 CellTemplate ,这样你就可以在那里放置自己的自定义控件。组合框。然后,你应该在那里推断出你需要的控件并将它绑定在你的课堂上
下面的粗略示例
<DataGrid.Columns>
<DataGridTemplateColumn Header="Bar Codes">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Ean, Converter={StaticResource EanListToString}}"></ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
...
答案 1 :(得分:1)
将DataGridTemplateColumn与HeaderTemplate一起使用,该HeaderTemplate具有用于过滤的TextBox输入。
<DataGridTemplateColumn Width="80" SortMemberPath="Naam" Header="Naam">
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<Grid>
<StackPanel Orientation="Vertical">
<TextBlock>Naam</TextBlock>
<TextBox Text="{Binding Delay=200, RelativeSource={RelativeSource AncestorType={x:Type UserControl }}, Path=DataContext.Filter.Naam, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>1
模型
public class Filter:INotifyPropertyChanged//Todo implement interface
{
private string name;
public string Name
{
get{return name;}
set{name = value; OnPropertyChanged("Name");}
}
}