Hi Leon,
Sorry for my late answer but your solution Doesn't work, because when I want to read CurrentControl.IsVisible or CurrentControl.IsEnabled they are always true even if it was setted to false. Again I am sure that is related to fact that I use my control inside a Collectionview ( on each row ! ) and it is reusing same control or something like that. But ! I have found a solution:
The key is to use that static dictionary , and now the values are correct !
public static Dictionary<Guid, bool> dicEnabled = new Dictionary<Guid, bool>();
public static Dictionary<Guid, bool> dicVisible = new Dictionary<Guid, bool>();
private bool isVisibleInternal => Id != Guid.Empty && dicVisible.ContainsKey(Id) ? dicVisible[Id] : true;
private bool isEnabledInternal => Id != Guid.Empty && dicEnabled.ContainsKey(Id) ? dicEnabled[Id] : true;
public SsSwitch()
{
InitializeComponent();
Id = Guid.NewGuid();
}
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == "IsVisible")
{
if (dicVisible.ContainsKey(Id))
dicVisible[Id] = IsVisible;
else dicVisible.Add(Id, IsVisible);
if (!IsVisible)
{
this.RemoveBinding(SsSwitch.IsOnProperty);
}
}
else if (propertyName == "IsEnabled")
{
if (dicEnabled.ContainsKey(Id))
dicEnabled[Id] = IsEnabled;
else dicEnabled.Add(Id, IsEnabled);
if (!IsEnabled)
{
this.RemoveBinding(SsSwitch.IsOnProperty);
}
}
}