小编Rya*_*uer的帖子

内置控件的WPF装饰器

我试图让一个不寻常的使用Adorner.当您将鼠标悬停在RichTextBox上时,Adorner(请参见下图)将显示在其上方,允许您将字符串列表添加到Adorner中包含的ListBox中.这用于将"标签"(àlaFlickr)添加到装饰元素中包含的通道.

装饰图

首先:这甚至可能吗?

大多数Adorners示例都展示了如何覆盖Adorner的OnRender方法来执行绘制形状之类的微不足道的事情.我能够使用它来渲染一组矩形,这些矩形创建了Adorner的灰色边框,如果RichTextBox的高度由于在显示Adorner时添加了额外的行文本而增加,它也会自动调整大小.

protected override void OnRender(DrawingContext drawingContext)
{
    SolidColorBrush grayBrush = new SolidColorBrush();
    grayBrush.Color = Color.FromRgb(153, 153, 153);

    // left
    drawingContext.DrawRectangle(grayBrush, null, new System.Windows.Rect(1, 1, 5, ActualHeight));
    // right
    drawingContext.DrawRectangle(grayBrush, null, new System.Windows.Rect(ActualWidth - 6, 1, 5, ActualHeight));
    //bottom
    drawingContext.DrawRectangle(grayBrush, null, new System.Windows.Rect(1, ActualHeight, ActualWidth - 2, 5));

    // for reasons unimportant to this example the top gray bar is rendered as part of the RichTextBox

}
Run Code Online (Sandbox Code Playgroud)

但是,添加控件稍微有点问题.一般来说,WPF的装饰需要在代码而不是XAML中添加子控件.使用DrawingContext adorner中描述的技术- 可以绘制stackpanel?,我已经学会了如何在Adorner的初始化程序中将子控件(如TextBox)添加到Adorner而没有任何问题.

然而,问题是将这些控件放置在Adorner中.

如果我可以创建一个灰色背景的网格并将其放置在Adorner的底部,我应该很高兴.我会假设(希望)自动调整基于随着标签的大小变化而自动调整Adorner大小的事情.

简而言之,假定这是可能的,任何人都可以建议创建该下部标记控制区的一个方式 …

.net c# wpf

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

棱镜组件参考失败:System.Windows.Interactivity

我有C#/ WPF Prism(v4.0)应用程序,它有一个持久的问题,加载/解析Prism库附带的System.Windows.Interactivity dll.我已经连续工作了三天试图调试/解决这个问题.我已经学会了很多关于.Net程序集的解决方案,但到目前为止我的问题没有运气,所以我想我会转而向StackOverflow社区寻求帮助.:)

我有一个模块作为更大的Prism应用程序的一部分运行,它需要引用System.Windows.Interactivity以添加行为.因此,我有一个XAML用户控件指定命名空间,如下所示:

<UserControl x:Class="MyApp.Modules.SourcesModule.myView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">
Run Code Online (Sandbox Code Playgroud)

然后我尝试在UserControl的子元素上设置行为,如下所示:

<ListBox Name="myListBox">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <i:InvokeCommandAction Command="{Binding SomeCommandOrOther}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

奇怪的是,该项目构建良好,并且当键入关联的代码隐藏文件时,我甚可以在System.Windows.Interactivity命名空间中获取Intellisense自动完成对象.

但是,仅在运行时,我在上面的ListBox元素上得到一个XamlParseException.

Could not load file or assembly 'System.Windows.Interactivity, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 
Run Code Online (Sandbox Code Playgroud)

InnerException的类型为System.IO.FileNotFoundException

"Could not load file or assembly 'System.Windows.Interactivity, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.":"System.Windows.Interactivity, PublicKeyToken=31bf3856ad364e35"
Run Code Online (Sandbox Code Playgroud)

...正如我从阅读有关汇编解决方案中学到的那样,通常会提出一个问题,解决一个强名称的汇编,而不仅仅是无法在磁盘上找到dll(正如异常类型所暗示的那样).

Fusion日志信息如下,包括有关所涉及程序集的部分绑定的警告:

=== Pre-bind state information === …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf prism visual-studio

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

标签 统计

.net ×2

c# ×2

wpf ×2

prism ×1

visual-studio ×1