I have a datatemplate for a viewmodel where an itemscontrol is bound against a CollectionViewSource (to enable sorting in xaml).
x:Static
is supposed to work in d:DataContext
, I think only d:DesignInstance or d:DesignData
could.d:IsDesignTimeCreatable=True
property in the d:DesignInstance
.It should generally look like this:
d:DataContext="{d:DesignInstance Type=vm:EquipmentViewModel,
IsDesignTimeCreatable=True}"
You could use the same ViewModel for both runtime and designtime, make a IsInDesignTime
property in you ViewModelBase
and return data appropriately.
Example:
private static bool? _isInDesignMode;
public static bool IsInDesignModeStatic
{
get
{
if (!_isInDesignMode.HasValue)
{
var prop = DesignerProperties.IsInDesignModeProperty;
_isInDesignMode
= (bool)DependencyPropertyDescriptor
.FromProperty(prop, typeof(FrameworkElement))
.Metadata.DefaultValue;
}
return _isInDesignMode.Value;
}
}
Note: I would encourage you to use StaticResources
(rather than DynamicResources
) for templates or styles that are not meant to change at runtime. Read this for more info.