Hi I found this questions
and apply his answer to my project. I'm implementing the same behavior.
but the thing is the property binding doesn't work.
I create the RoleToVisibilityConverter class and make some test, calling the convert
RoleToVisibilityConverter conv = new RoleToVisibilityConverter();
conv.Convert((object)Thread.CurrentPrincipal,cbo_organismo.GetType(),(object)"editor",System.Globalization.CultureInfo.CurrentCulture);
this work find, then i add the resources to my usercontrol
<UserControl.Resources>
<fundafe:RoleToVisibilityConverter x:Key="roleConverter"/>
</UserControl.Resources>
and make the binding to my button control
<Button Margin="0,0,0,0" Visibility="{Binding Source=Thread.CurrentPrincipal, Path=CurrentPrincipal, Converter={StaticResource roleConverter}, ConverterParameter=editor}" VerticalAlignment="Center" HorizontalAlignment="Left" Name="btn_Eliminar" Click="btn_Eliminar_Click" Width="Auto" Height="25" Background="Transparent" BorderBrush="Transparent">
<Image Name="img_eliminar" Width="48" Source="imagenes/borrar.png" Height="19" />
</Button>
after running my application, the button is still visible.
if i'm hardcoding the Visibility property the button is hiden
btn_Eliminar.Visibility=(Visibility)conv.Convert((object)Thread.CurrentPrincipal,cbo_organismo.GetType(),(object)"editor",System.Globalization.CultureInfo.CurrentCulture)
Any suggestion?
Note: I'cant use the last approach because in my real scenario the button is part of a DataTemplate for a ListView, and even if a capture the button using the TreeHelper the ListView only apply the change to the first items due to virtualization