3

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 ....
Community
  • 1
  • 1
Reza M.
  • 1,205
  • 14
  • 33

1 Answers1

7

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);
  }
}
Liz
  • 8,780
  • 2
  • 36
  • 40
  • Didn't know about the xmlns so I added it... This is what it looks like right now `xmlns:Controls="clr-namespace:VideoCapture"` ` Type here to search text ` – Reza M. Mar 23 '11 at 00:35
  • But still getting error controls is undeclared prefix and athe attachable property Watermark was not found in type WatermarkService – Reza M. Mar 23 '11 at 00:37
  • Nvm, just vs2010 being a bit grumpy, I get no errors now thanks but still doesn't display, I'll try figuring that out. Really new at wpf :P – Reza M. Mar 23 '11 at 00:41
  • Thanks it works with a new textbox, gotta figure out why it doesn't with my old ones. – Reza M. Mar 23 '11 at 01:34
  • In my case this didnt work because in "xmlns:controls ..." the word "controls" has to start with lower case. "xmlns:Controls" did not work. – Gener4tor Jun 05 '23 at 13:59