Let me describe the problem this way I have created a custom control and Users can use custom control in this way
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/customControl;component/ThemeResources/Light.xaml"/>
<ResourceDictionary Source="/customControl;component/ThemeResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
There is no problem with this method and all resources can be identified by VS IntelliSense.
Now to make it easier to use custom control, I use the following class:
public class Theme : ResourceDictionary
{
public Theme()
{
if (DesignerHelper.IsInDesignMode)
{
MergedDictionaries.Add(new ResourceDictionary
{
Source = new Uri("pack://application:,,,/customControl;component/ThemeResources/Light.xaml")
});
MergedDictionaries.Add(new ResourceDictionary
{
Source = new Uri("pack://application:,,,/customControl;component/ThemeResources.xaml")
});
}
else
{
UpdateResource();
}
}
private Uri _source;
public new Uri Source
{
get => DesignerHelper.IsInDesignMode ? null : _source;
set => _source = value;
}
public string Name { get; set; }
private void UpdateResource()
{
if (DesignerHelper.IsInDesignMode) return;
MergedDictionaries.Clear();
MergedDictionaries.Add(new ResourceDictionary
{
Source = new Uri("pack://application:,,,/customControl;component/ThemeResources.xaml")
});
MergedDictionaries.Add(new ResourceDictionary
{
Source = new Uri("pack://application:,,,/customControl.Controls;component/ThemeResources/Light.xaml")
});
}
}
Now this way we can use custom control:
<ResourceDictionary.MergedDictionaries>
<ui:Theme/>
</ResourceDictionary.MergedDictionaries>
Now the problem is that None of the resources are not detected by IntelliSense But if we write the style name ourselves, we can use resources.
Why does this problem occur? How to solve this problem?
XAML intellisense needs to work without running any code and/or when solution is not built. Thus it does not know that creating Theme will fill it in with pack://application:,/customControl;component/Themes/Generic.xaml
.