突出显示Listbox DataTemplate(WPF)中的文本块中的部分文本

时间:2016-07-10 18:17:33

标签: c# wpf xaml listbox datatemplate

您好我想要突出显示texblock中文本的一部分,并且该文本块位于列表框的datatemplate中。我正在尝试这样做,因为用户正在通过列表搜索textBOX中的文本。 (这与在Windows文件浏览器中搜索时类似) 文本块绑定到自定义类的属性。

这是列表框DataTemplate

的XAML
<ListBox Grid.Row="1" HorizontalContentAlignment="Stretch" Name="
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid Name="me" Height="25" Margin="0,2">
                <DockPanel>
                    <TextBlock DockPanel.Dock="Left" FontSize="15" TextAlignment="Center" Text="{Binding ProductID}"></TextBlock>
                    <Image HorizontalAlignment="Right" MouseUp="listboxStockPickItems_AddClick" DockPanel.Dock="Right" VerticalAlignment="Stretch" Margin="0,0,5,0" Cursor="Hand" Width="20" Height="20" Source="/Images/addItem.png"></Image>
                </DockPanel>
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

这是自定义类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace UCServer
{
[Serializable]
public class Articulo
{
    public int ID { get; set; }

    public string ProductID { get; set; }

    public string Name { get; set; }

    public int Amount { get; set; }

    public double Price { get; set; }
}
}

任何帮助将不胜感激!

0 个答案:

没有答案
相关问题