Hi,
I created a custom control deriving from ContextMenu in VB.net language.
It's default style is defined in the Generic.XAML being in the same assembly as the custom control. To configure this I added this line to the AssemblyInfo.vb:
<Assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)>
In the controls shared(static) constructor I said that the control has it's own control style:
DefaultStyleKeyProperty.OverrideMetadata(GetType(FilterContextMenu), New FrameworkPropertyMetadata(GetType(FilterContextMenu)))
I added a test project (VB.net) to the solution, referenced the assembly of the control, added namespaces, etc and it works. The visual tree in the WPF tree visualizer looks like this:
But when I reference the custom control assembly in another solution (C# language) the visual tree gets broken and looks like this:
The controls default style in the generic.xaml looks like this.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cv="clr-namespace:DataGridContextMenuFilter.Converter" xmlns:local="clr-namespace:DataGridContextMenuFilter.FilterControls"><cv:InvalidDateToNullConverter x:Key="InvalidDateToNullConverter" /><cv:InvalidBooleanToNullConverter x:Key="InvalidBooleanToNullConverter" /><Style TargetType="{x:Type local:FilterContextMenu}"><Setter Property="SnapsToDevicePixels" Value="True" /><Setter Property="Grid.IsSharedSizeScope" Value="true" /><Setter Property="HasDropShadow" Value="True" /><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="local:FilterContextMenu"><Menu Name="FilterMenu"><Menu.ItemsPanel><ItemsPanelTemplate><VirtualizingStackPanel Orientation="Vertical" /></ItemsPanelTemplate></Menu.ItemsPanel><TextBox Name="CriteriaValue" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:FilterContextMenu, AncestorLevel=1}, Path=CriteriaValue, UpdateSourceTrigger=PropertyChanged}" /><DatePicker Name="CriteriaValueDate" SelectedDate="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:FilterContextMenu, AncestorLevel=1}, Path=CriteriaValue, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InvalidDateToNullConverter}}" /><ComboBox Name="CriteriaValueEnum" DisplayMemberPath="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:FilterContextMenu, AncestorLevel=1}, Path=DisplayMemberPath, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:FilterContextMenu, AncestorLevel=1}, Path=CriteriaValueList, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:FilterContextMenu, AncestorLevel=1}, Path=CriteriaValue, UpdateSourceTrigger=PropertyChanged}" /><CheckBox Name="CriteriaCheckBox" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:FilterContextMenu, AncestorLevel=1}, Path=CriteriaValue, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InvalidBooleanToNullConverter}}" IsThreeState="True" /><TextBlock Name="FilterNotAvailable" Width="200" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:FilterContextMenu, AncestorLevel=1}, Path=FilterNotAvailableMessage, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" /><ListBox Name="CompareOperationList" Width="200" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:FilterContextMenu, AncestorLevel=1}, Path=CompareOperations, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"><ListBox.ItemContainerStyle><Style TargetType="ListBoxItem"><Style.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="Background" Value="LightGray" /></Trigger></Style.Triggers></Style></ListBox.ItemContainerStyle></ListBox><local:FilterButton x:Name="RemoveFilterButton" Content="Remove filter" IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:FilterContextMenu, AncestorLevel=1}, Path=GroupFilter.IsFilterActive}" /><ItemsPresenter /> </Menu></ControlTemplate></Setter.Value></Setter></Style></ResourceDictionary>
Any idea why the control's visual tree gets broken would be great.
Thank you!