Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to assign a datatemplate to textbox wpf
    primarykey
    data
    text
    <p>TextBox is supposed to show masked dollar amount for certain access privileges. I created a converter class(inheriting from IValueConverter) to handle masking by implementing the convert method.</p> <pre><code>public object Convert(object value, Type targetType, object parameter, CultureInfo culture) </code></pre> <p>The third parameter is passed true if masking is needed else false.</p> <p>Called like this:</p> <pre><code>CurrencyCOnverter converter = new CurrencyConverter(); this._textbox1.Text = converter.Convert(Amount, typeof(string), !this.IsSuperUser, CurrentCulture).ToString(); </code></pre> <p>I have about 12 textboxes on UI. Instead of doing this at 12 places, I defined DataTemplates in Resource dictionary which looks like this:</p> <pre><code>&lt;DataTemplate x:Key="MaskNormalBackgroundTbx"&gt; &lt;TextBlock TextAlignment="Right" VerticalAlignment="Center" TextWrapping="WrapWithOverflow" Text="{Binding "Amount" Converter={StaticResource CurrencyDisplayConverter}, ConverterParameter=true}" /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="NoMaskNormalBackgroundTbx"&gt; &lt;TextBlock TextAlignment="Right" VerticalAlignment="Center" TextWrapping="WrapWithOverflow" Text="{Binding "Amount" Converter={StaticResource CurrencyDisplayConverter}, ConverterParameter=false}" /&gt; &lt;/DataTemplate&gt; </code></pre> <p>My Question: Is there a way I can assign this template to textbox by creating a custom textbox just like we assign data templates for ListBox?</p> <p>Thanks,</p> <p>Megan.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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