Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure about replacing the default DataTemplate, but you can use a ValueConverter to pass display ToString in the case of certain types and an empty string otherwise. Here's some code (note that the typeb textblock doesnt have the converter on it to show what it looks like normally):</p> <p>.xaml:</p> <pre><code>&lt;Window x:Class="EmptyTemplate.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:loc="clr-namespace:EmptyTemplate" Title="Window1" Height="300" Width="300"&gt; &lt;Window.Resources&gt; &lt;loc:AType x:Key="atype"/&gt; &lt;loc:BType x:Key="btype"/&gt; &lt;loc:TypeConverter x:Key="TypeConverter"/&gt; &lt;/Window.Resources&gt; &lt;StackPanel&gt; &lt;Button Content="{Binding Source={StaticResource atype}, Converter={StaticResource TypeConverter}}"/&gt; &lt;Button Content="{Binding Source={StaticResource btype}, Converter={StaticResource TypeConverter}}"/&gt; &lt;TextBlock Text="{Binding Source={StaticResource atype}, Converter={StaticResource TypeConverter}}"/&gt; &lt;TextBlock Text="{Binding Source={StaticResource btype}}"/&gt; &lt;/StackPanel&gt; &lt;/Window&gt; </code></pre> <p>.xaml.cs:</p> <pre><code>namespace EmptyTemplate { /// &lt;summary&gt; /// Interaction logic for Window1.xaml /// &lt;/summary&gt; public partial class Window1 : Window { public Window1() { InitializeComponent(); } } public class AType { } public class BType { } public class TypeConverter : IValueConverter { public DataTemplate DefaultTemplate { get; set; } #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value.GetType() == typeof(AType)) { return value.ToString(); } return DefaultTemplate; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } } </code></pre>
 

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