我有一个内容控件,它根据当前状态显示动态内容。这一切都很好,但在设计时,我希望它显示默认状态。有什么办法可以使用ValueConverter
orFallbackValue
或其他东西来做到这一点?
XAML
<ContentControl Content="{Binding State,
Converter={StaticResource InstallationStateToControlConverter}}" />
C#
class InstallationStateToControlConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
//return controls depending on the state
switch ((InstallationState)value)
{
case InstallationState.LicenceAgreement:
return new LicenceAgreementControl();
default:
return new AnotherControl();
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
更新
根据 Viv 的问题,我已将以下内容添加到我的 XAML 中,它可以编译,但我仍然在设计器中看不到任何内容?
d:DataContext="{d:DesignInstance Type=local:LicenceAgreementControl, IsDesignTimeCreatable=True}"