Watermark using John Myczek's Class
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 wi开发者_Python百科th 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);
}
}
精彩评论