Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Answer is to long for comment</h3> <p>Arnaud Weil brought me on the right way:</p> <p>To access the Property 'IsAdministrator' in ViewModel from the Datatemplate, I gave the UserControl a Name e.g.:</p> <pre><code>&lt;UserControl x:Class="blanked out" x:Name="this" </code></pre> <p>Used the code from Arnaud with some modifications, to inherit the Binding to the ViewModel from UserControl</p> <pre><code>&lt;UserControl.Resources&gt; &lt;BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/&gt; &lt;helper:NotBooleanToVisibilityConverter x:Key="NotBooleanToVisibilityConverter"/&gt; &lt;DataTemplate x:Key="myTemplate"&gt; &lt;Grid&gt; &lt;Grid Visibility="{Binding DataContext.IsAdministrator, ElementName=this, Converter={StaticResource BooleanToVisibilityConverter}}"&gt; &lt;!-- Content for admin --&gt; &lt;TextBlock Background="Yellow" Margin="3" Text="ICH BIN ADMNIN; JUCHUUU" /&gt; &lt;/Grid&gt; &lt;Grid Visibility="{Binding DataContext.IsAdministrator, ElementName=this, Converter={StaticResource NotBooleanToVisibilityConverter}}"&gt; &lt;!-- Content for user --&gt; &lt;Image Name="logo" Source="/blanked out" HorizontalAlignment="Center" VerticalAlignment="Center" /&gt; &lt;/Grid&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/UserControl.Resources&gt; </code></pre> <p>And for the inverted BooleanToVisibilityConverter:</p> <pre><code>using System; using System.Globalization; using System.Windows; using System.Windows.Data; namespace blankedout.Helper { [ValueConversion(typeof(bool), typeof(Visibility))] public class NotBooleanToVisibilityConverter:IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var boolValue = (bool)value; return !boolValue ? Visibility.Visible : Visibility.Hidden; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } } </code></pre> <p>Thanks once again to Arnaud Weil</p> <p>Regards</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.
    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