问题描述
限时送ChatGPT账号..嘿,我尝试实现 John 制作的类水印.>
我被卡住了,想知道是否有人可以帮助我......添加了提到的 2 个课程并在 wpf 上:
<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>在此处键入以搜索文本</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:关键词]
发布评论