0
我对WPF很新,可以真正做一些帮助。 反正有绑定ImageAwesome
对象(Font-Awesome)从ViewModel属性吗?现在,我的ViewModel在实例化时会创建一个ImageAwesome
对象,然后使用属性SpinIcon
访问该对象。从ViewModel属性中绑定WPF中的ImageAwesome对象
视图模型
public class DefaultPageViewModel : BaseViewModel
{
private ImageAwesome _spinIcon;
public DefaultPageViewModel()
{
_spinIcon = new ImageAwesome();
_spinIcon.Icon = FontAwesomeIcon.Spinner;
_spinIcon.Height = 10;
}
public ImageAwesome SpinIcon {
get
{
return _spinIcon;
}
set
{
if(value != _spinIcon)
{
_spinIcon = value;
OnPropertyChanged("SpinIcon");
}
}
}
}
我可以绑定的SpinIcon
各个属性,如下图所示,但这会导致大量的重复代码,我正在努力避免的。
用户控件
<UserControl.Resources>
<default:DefaultPageViewModel x:Key="DefaultVM" />
<SolidColorBrush x:Key="ImageBrush" Color="LightBlue" />
</UserControl.Resources>
<Grid>
<fa:ImageAwesome Icon="{Binding SpinIcon.Icon, Source={StaticResource DefaultVM}}" />
</Grid>
</UserControl>
任何帮助将非常感激。
我不知道你能做到这一点!非常感谢你! – Kitson88