Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to reuse the same Watermark TextBox
    text
    copied!<p>I have a WatermarkTextBox that inherits TextBox and I have x:Name="TestASearch" which will be called in the listview to display the search returned from the method textboxsearch_TextChanged.</p> <pre><code> &lt;controls:WatermarkTextBox x:Name="TestASearch" Grid.Column="2" Grid.Row="0" Margin="10,61,0,10" SelectAllOnGotFocus="True" Background="White" TextChanged="textboxsearch_TextChanged"&gt; &lt;controls:WatermarkTextBox.Watermark&gt; &lt;TextBlock FontStyle="Italic" Text="Enter search text…" Width="116"/&gt; &lt;/controls:WatermarkTextBox.Watermark&gt; </code></pre> <p></p> <p>WatermarkTextBox class</p> <pre><code> public WatermarkTextBox() { FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(WatermarkTextBox), new FrameworkPropertyMetadata(typeof(WatermarkTextBox))); } </code></pre> <p>Now I want to use the same concept except that I want a different x:Name =TestBSearch and wanted to use TextChanged="textboxsearch_TextChanged"</p> <pre><code> &lt;controls:WatermarkTextBox x:Name="TestBSearch" Grid.Column="2" Grid.Row="0" Margin="10,61,0,10" SelectAllOnGotFocus="True" Background="White" TextChanged="textboxsearch_TextChanged"&gt; &lt;controls:WatermarkTextBox.Watermark&gt; &lt;TextBlock FontStyle="Italic" Text="Enter search text…" Width="116"/&gt; &lt;/controls:WatermarkTextBox.Watermark&gt; &lt;/controls:WatermarkTextBox&gt; </code></pre> <p>When I try this I get error "PropertyMetadata is already registered for type 'WatermarkTextBox'." How can I reuse the same code?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload