使用 John Myczek 的类的水印

编程入门 行业动态 更新时间:2024-10-07 20:31:06
本文介绍了使用 John Myczek 的类的水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

嘿,我尝试实现 John 制作的类水印.>

我被卡住了,想知道是否有人可以帮助我......添加了提到的 2 个课程并在 wpf 上:

<ComboBox Height="23" Horizo​​ntalAlignment="Right" Margin="0,184,664,0" x:Name="cbVideoDevices" VerticalAlignment="Top" Width="316" Initialized="cbVideoDevices_Initialized" SelectionChanged="cbVideoDevices_SelectionChanged"><Controls:WatermarkService.Watermark><TextBlock>在此处键入以搜索文本</TextBlock></Controls:WatermarkService.Watermark></组合框></AdornerDecorator>

无论我尝试什么,我都不断收到错误消息,因为控件不存在,或者属性没有退出.我在他的课程中没有发现任何错误,所以我认为参考文献很好,但在我看来 System.Windows.Control 丢失了......但我找不到它来添加它......

任何帮助,非常感谢.

在 Liz 的帮助下,我完成了这项工作,但要让任何人知道,谁在使用它.

AdornerDecorator 在所有东西上创建一个盒子......为 AdornerDecorator 创建 Margin 并将其移动到所需位置边距和对齐与显示水印的位置一致....

解决方案

我尝试了这个例子,它对我有用.

但是,我确实注意到了以下几点:

这些类没有指定命名空间,所以我为两个类都添加了一个.就我而言,水印".

命名空间水印{公共静态类 WatermarkService{...}}

内部"中的 WatermarkAdorner 类,但这不会打扰您,除非它位于不同的程序集 (dll) 中.如果是,则将其设为公开"

然后在xaml中,我添加了一个命名空间声明

xmlns:Controls="clr-namespace:Watermark"

那时一切正常.

我稍微简化的 xaml 如下所示:

<ComboBox 高度="23" x:Name="cbVideoDevices"初始化=cbVideoDevices_Initialized"SelectionChanged="cbVideoDevices_SelectionChanged"><controls:WatermarkService.Watermark><TextBlock>在此处键入以搜索文本</TextBlock></controls:WatermarkService.Watermark></组合框></AdornerDecorator>

除了去除你的边距和对齐之外,它与你的基本相同.

这有帮助吗?

作为旁注,我不喜欢在组合框中选择项目时仍然显示水印的事实,因此我将 WatermarkService 中的 Control_Loaded 方法更改如下:

private static void Control_Loaded(object sender,RoutedEventArgs e){控制控制=(控制)发送者;if(ShouldShowWatermark(control)){显示水印(控制);}别的{移除水印(控制);}}

Hey, I tried implementing a class John madeWatermark.

I'm stuck and wondered if anyone can help me .... Added the 2 classes mentioned and on the wpf:

<AdornerDecorator>
        <ComboBox Height="23" HorizontalAlignment="Right" Margin="0,184,664,0" x:Name="cbVideoDevices" VerticalAlignment="Top" Width="316" Initialized="cbVideoDevices_Initialized" SelectionChanged="cbVideoDevices_SelectionChanged">
            <Controls:WatermarkService.Watermark>
                <TextBlock>Type here to search text</TextBlock>
            </Controls:WatermarkService.Watermark>
        </ComboBox>
    </AdornerDecorator>

Whatever I try, I keep getting errors as the Control doesn't exist, or the Property does not exit. I get no errors in his classes so I figured the references are good but it seemed to me the System.Windows.Control is missing.... but I can't find it to add it ...

Any help, much appreciated.

Edit: With Liz's help I got this to work but to let anyone know, who does use this.

The AdornerDecorator Creates a box over everything ..... Create the Margin for the AdornerDecorator and move that to desired position Margin and alignments screw with where the watermark is shown ....

解决方案

I tried the example and it works for me.

However, I did notice the following:

The classes did not specify a namespace, so I added one for both classes. In my case "Watermark".

namespace Watermark
{
  public static class WatermarkService
  {
   ...
  }
}

The WatermarkAdorner class in "internal", but that shouldn't bother you unless it is in a different assembly (dll). If it is then make it "public"

Then in the xaml, I added a namespace declaration

xmlns:Controls="clr-namespace:Watermark"

At that point everything worked fine.

My slightly simplified xaml looks like this:

<AdornerDecorator >
      <ComboBox Height="23"  x:Name="cbVideoDevices"   
                             Initialized="cbVideoDevices_Initialized"                       
                             SelectionChanged="cbVideoDevices_SelectionChanged">
        <controls:WatermarkService.Watermark>
          <TextBlock>Type here to search text</TextBlock>
        </controls:WatermarkService.Watermark>
      </ComboBox>
    </AdornerDecorator>

Other than removing your margins, and alignment, it is basically the same as yours.

Does that help?

As a side-note I didn't like the fact that the watermark still showed when an item was selected in the combobox, so I changed the Control_Loaded method in the WatermarkService as follows:

private static void Control_Loaded(object sender,RoutedEventArgs e)
{
  Control control = (Control)sender;
  if(ShouldShowWatermark(control))
  {
    ShowWatermark(control);
  }
  else
  {
    RemoveWatermark(control);
  }
}

这篇关于使用 John Myczek 的类的水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 21:31:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142701.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:水印   John   Myczek

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!