This isn't so much a problem, but rather an annoyance... I've put together a conditional class to show different views dependent on which radio button is selected. It works as expected, but I can't get rid of the blue squiggle under my 'SwitchCase' property.
Case class:
public class Case : ContentControl
{
public static readonly DependencyProperty SwitchCaseProperty = DependencyProperty.Register("SwitchCase",
typeof(object), typeof(Case), new PropertyMetadata() { PropertyChangedCallback = OnPropChanged });
public object? SwitchCase
{
get => GetValue(SwitchCaseProperty);
set => SetValue(SwitchCaseProperty, value);
}
public object? SwitchValue { get; set; }
public object? SwitchContent { get; set; }
private static void OnPropChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is Case _case)
{
_case.Content = _case.SwitchCase.ToString() == _case.SwitchValue.ToString() ? _case.SwitchContent : null;
}
}
}
Implementation:
<Grid Grid.Row="1"
TextElement.Foreground="#c2c2c2">
<conditional:Case SwitchCase="{Binding ElementName=HomeNavButton, Path=IsChecked}"
SwitchValue="True"
SwitchContent="{StaticResource HomeView}" />
<conditional:Case SwitchCase="{Binding ElementName=AccountNavButton, Path=IsChecked}"
SwitchValue="True"
SwitchContent="{StaticResource AccountView}" />
<conditional:Case SwitchCase="{Binding ElementName=UserNavButton, Path=IsChecked}"
SwitchValue="True"
SwitchContent="{StaticResource LoginView}" />
</Grid>
It runs fine, but I can't see why the null exception applies when all 3 'navbuttons' exist.
Any ideas?
Edit
The following error appears on each of the SwitchCase statements in xaml editor:
Case.SwitchCase
Object reference not set to an instance of an object