In WPF project, references only used in xaml is not copied to bin folder even with CopyLocal
set to true, as complained in this post. With MVVM pattern, it is common that 3rd party controls are used with no code-behind references at all.
Inspired by this post, I am using the workaround below. It's easy enough, however, one has to manually maintain the variable list in sync with those actually used in the XAML files across the project, which are subject to constant changes. My question is whether there is a real solution or a better workaround? (I am aware of the idea of using post-build script, which IMHO is less discover-able and more vulnerable to changes.)
internal static class BuildTricker
{
private static readonly RadTreeView radTreeView;
static BuildTricker()
{
// Set and get once to avoid compiler optimization.
radTreeView = null;
if (radTreeView != null)
{
throw new InvalidOperationException("This should never happen.");
}
}
}
The workaround I use is to make sure the item has a name defined in the XAML. This causes it to create an instance for it in the generated code behind (partial) class. This is enough for the reference following system to detect the reference, and copy in the dependency dll.
e.g.:
<ts:HorizontalToggleSwitch IsChecked="{Binding ShowMyItemsOnly}"
CheckedContent="Show My Items Only"
UncheckedContent="Show All Items"
x:Name="NameRequiredForCopyLocal">
This is a known problem with XAML-Code. There is something strange during parsing the XAML-Code because VisualStudio knows, that the corresponding DLL is used. For my case it helped to create an Attribute of any object from the specific DLL in the code behind class or any class in the project. (Workaround)
For example:
// This is only for the build process, to copy target assembly to output.
private RadTreeView _TreeViewForCompiler;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With