我尝试以编程方式更改 Packicon 的种类。
更新的问题:
这是我现在的代码:
我现在实现了接口 INotifyPropertyChagned:
public partial class OwnExtendedMessageBox : Window, INotifyPropertyChanged
然后我添加了这些行
//property of Binding changed
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
然后我这样称呼它
switch (MessageBoxIcon)
{
case OwnMessageBoxIcon.None:
MessageBoxIconKind = PackIconKind.Box;
break;
case OwnMessageBoxIcon.Info:
MessageBoxIconKind = PackIconKind.Information;
break;
case OwnMessageBoxIcon.Warning:
MessageBoxIconKind = PackIconKind.Warning;
break;
case OwnMessageBoxIcon.Error:
MessageBoxIconKind = PackIconKind.Error;
break;
default:
MessageBoxIconKind = PackIconKind.Box;
break;
}
OnPropertyChanged("MessageBoxIconKind");
WPF:
<materialDesign:PackIcon Kind="{Binding MessageBoxIconKind}" Foreground="{DynamicResource PrimaryHueDarkForegroundBrush}" ...
我也用字符串尝试过,但它也不起作用