标签: itemscontrol

如何使用突出显示的查询术语在WPF项目控件中显示搜索结果

我想在WPF ItemsControl中显示搜索结果,并突出显示查询字词.

我使用的搜索引擎,带有Highlighter插件的Lucene.Net,返回带有标记的查询字符串,如下所示:

...these <Bold>results</Bold> were found to be statistically significant...
Run Code Online (Sandbox Code Playgroud)

我可以指示Highlighter插件使用任何标记标记来包装查询术语.我不限于<Bold>上面例子中的标签.对于WPF,我可能会使这些<Run/>元素附加一个样式.

挑战是获取我已经给出的字符串并将其呈现为我在搜索结果中使用的数据模板中的"实际XAML".换句话说,我想看到这样的事情:

......这些结果被发现具有统计学意义......

但我正在努力解决如何在数据模板中将数据绑定与XAML字符串的动态呈现相结合的问题.这里最好的方法是什么?

  1. 使用UserControl显示每个搜索结果并XamlReader.Load()从代码隐藏调用?
  2. 构造包含搜索结果字符串的FlowDocument并使用FlowDocumentScrollViewer显示结果?
  3. 还有其他东西......?

wpf xaml datatemplate itemscontrol

8
推荐指数
3
解决办法
9547
查看次数

WPF自定义面板/控件创建 - "甜甜圈"

我希望创建一个自定义面板或控件来创建一个非常特殊类型的项目.

基本上,目的是有一个控件,你可以给出一个对象列表,它会将每个对象放入一个按钮.问题是按钮应该像圆环一样布置成圆形.与下图相似.

甜甜圈图表

但是现在想象一下,如果可以的话,每个彩色部分都是一个按钮.它们也具有按钮的所有功能,如鼠标悬停和事件.

所以,问题首当其冲的是:我应该采用什么样的技术来创造这种控制?有没有办法在按钮上进行某种"曲率"变换?

看起来我真的想在这里找两件事,对吧?

我的意思是,我可以将列表中的每个项目放入一个ItemsControl,它有一个按钮作为其ItemTemplate.所以我需要的是两件事:

第一个是径向布局面板(我见过其中的一些).

第二种方法是让每个按钮都有某种旋转和曲率变换.

有任何想法吗?

wpf panel itemscontrol radial

8
推荐指数
1
解决办法
1461
查看次数

如何为ItemsControl中的项添加边框?

我正在尝试为项目控件中的每个项目设置边框.以下是我的XAML代码.但这不起作用.

<ItemsControl.ItemContainerStyle>
    <Style>
        <Setter Property="Control.BorderThickness" Value="5" />
        <Setter Property="Control.BorderBrush" Value="Black" />
    </Style>
</ItemsControl.ItemContainerStyle>
Run Code Online (Sandbox Code Playgroud)

wpf xaml styles border itemscontrol

8
推荐指数
1
解决办法
1万
查看次数

将ItemsControl中的新项目滚动到视图中

我有一个ItemsControl数据绑定到ObservableCollection.我在后面的代码中有这个方法,它在列表中添加了一个新模型.然后我想将新项目(在列表底部)滚动到视图中.

ItemsControl当我查询大小时,我认为它的大小尚未更新,因为ActualHeight模型的添加之前和之后是相同的.此代码的效果是滚动到略高于新项目的点.

我怎么知道新的东西ActualHeight会是什么?

这是我的代码:

        ViewModel.CreateNewChapter();
        var height = DocumentElements.ActualHeight;
        var width = DocumentElements.ActualWidth;
        DocumentElements.BringIntoView(new Rect(0, height - 1, width, 1));
Run Code Online (Sandbox Code Playgroud)

data-binding wpf datatemplate itemscontrol

7
推荐指数
1
解决办法
7368
查看次数

WPF在ItemsControl的ToolTip中显示来自多个DataContexts的数据

我正在尝试显示由ItemsControl需要从概念上不相关的源提取数据的项目生成的工具提示.例如,假设我有一个Item类,如下所示:

public class Item
{
    public string ItemDescription { get; set; }
    public string ItemName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我可以使用工具提示在ItemsControl中显示Item,如下所示:

<ItemsControl x:Name="itemsControl" ItemsSource="{Binding Items}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding ItemName}">
                <TextBlock.ToolTip>
                    <ToolTip>
                        <TextBlock Text="{Binding ItemDescription}" />
                    </ToolTip>
                </TextBlock.ToolTip>
            </TextBlock>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)

但说我有一个可以通过访问其他属性DataContextItemsControl.有没有办法从工具提示中做到这一点?例如,

<ItemsControl x:Name="itemsControl" ItemsSource="{Binding Items}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding ItemName}">
                <TextBlock.ToolTip>
                    <ToolTip>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <TextBlock Text="{Binding ItemDescription}" />
                            <TextBlock Grid.Row="1" Text="{Bind this to another property of the …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf datacontext tooltip itemscontrol

7
推荐指数
1
解决办法
6862
查看次数

Silverlight:DataGrid就像在ItemsControl中进行分组一样

是否可以在Silverlight中的ItemsControl或Listbox中对项目进行分组?这些控件绑定到DomainDataSource.

或者是否有任何第三方控件执行此操作?

更新:

这是我想要创建的UI.

替代文字

silverlight grouping listbox itemscontrol

7
推荐指数
1
解决办法
4607
查看次数

排序EF4 EntityCollection <T>的最简单方法是什么?

我想为绑定到ItemsControl(在xaml中)的EntityCollection添加一些排序.我也想尽可能简单地做.看来这是不可能的.

如果我将集合包装在实体中的集合属性的"已排序"版本中,则会丢失集合更改通知.我不能使用CollectionViewSource,因为实体集合的BindingListCollectionView不支持对某些该死的原因进行排序(注意:我已经看到了带有"脏"黑客的博客帖子来解决这个问题,所以请不要回答那个kthx ).

是否有一个简单的(几行xaml,几行代码,无论如何)实现这个方法?

sorting itemscontrol entity-framework-4 entitycollection

7
推荐指数
1
解决办法
2099
查看次数

如何增加填充显示项组合框?

我想编写一个组合框的XAML模板来增加项目之间的空格/填充.我搜索了这个,但几乎最终得到了ItemsPresenter:

<ItemsPresenter x:Name="ItemsPresenter"
                KeyboardNavigation.DirectionalNavigation="Contained"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
Run Code Online (Sandbox Code Playgroud)

如何使用此模板格式化项目(边框,填充,字体...)?请帮忙.

wpf xaml templates combobox itemscontrol

7
推荐指数
1
解决办法
7076
查看次数

使用MVVM通过拖放重新排序ItemsControl

我最近问了一个关于如何使用Drag and Drop重新排序ItemsControl的问题(ItemsControl拖放).答案目前很有用(下面的代码),但现在我正在尝试实现MVVM,当前的解决方案需要访问视图中的项目.任何想法如何改变这与MVVM一起工作?我计划将附加属性绑定到命令,但我不知道如何摆脱诸如以下的行:int index = (int)(e.GetPosition(DimsContainer).X / width);

当前的拖放代码:

private void DimsContainer_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        _isDown = true;
        _startPoint = e.GetPosition(this.DimsContainer);
    }

    private void DimsContainer_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        _isDown = false;
        _isDragging = false;

        if (_realDragSource != null)
        {
            _realDragSource.ReleaseMouseCapture();
        }
    }

    private void DimsContainer_PreviewMouseMove(object sender, MouseEventArgs e)
    {
        if (_isDown)
        {
            if ((_isDragging == false) &&
                ((Math.Abs(e.GetPosition(this.DimsContainer).X - _startPoint.X) >
                    SystemParameters.MinimumHorizontalDragDistance) ||
                 (Math.Abs(e.GetPosition(this.DimsContainer).Y - _startPoint.Y) >
                    SystemParameters.MinimumVerticalDragDistance)))
            {
                _isDragging = true;
                _realDragSource = e.Source …
Run Code Online (Sandbox Code Playgroud)

c# wpf drag-and-drop itemscontrol mvvm

7
推荐指数
1
解决办法
8866
查看次数

创建自定义itemscontrol

我正在尝试创建一个源自的自定义控件ItemsControl.将ItemsControl被初始化的项目,但他们没有显示.

itemsControl:

public class PipeControl : ItemsControl 
{
    static PipeControl()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(PipeControl), new FrameworkPropertyMetadata(typeof(PipeControl)));                    
    }

    public PipeControl()
    {
        Checkers = new ObservableCollection<Checker>();
        Checkers.Add(new Checker());
        Checkers.Add(new Checker());
        Checkers.Add(new Checker());
        Checkers.Add(new Checker());
        Checkers.Add(new Checker());           
    }

    public ObservableCollection<Checker> Checkers 
    {
        get;
        set;               
    }        
}    
Run Code Online (Sandbox Code Playgroud)

主题资源字典:Generic.xaml

<Style TargetType="{x:Type local:PipeControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:PipeControl}">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">                                        
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>

    <Setter Property="ItemTemplate">
        <Setter.Value>
            <DataTemplate DataType="{x:Type local:Checker}">
                <Ellipse Fill="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />                    
            </DataTemplate>                
        </Setter.Value>            
    </Setter> …
Run Code Online (Sandbox Code Playgroud)

wpf custom-controls itemscontrol

6
推荐指数
1
解决办法
1万
查看次数