Had created blank WPF application in .Net Core 3.1, added MahApps Metro package 2.0.0. Had added simple SplitButton and implemented simple ViewModel to show items in SplitButton. This works fine.
Split button XAML code:
<MahApps:SplitButton Style="{DynamicResource SplitButtonStyle}"
Name="BrowserList"
MinWidth="80"
BorderThickness="1"
BorderBrush="LightGray"
MinHeight="31"
Width="120"
Margin="5,0,0,0"
ItemsSource="{Binding BrowsersAll, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
IsEnabled="true" >
<MahApps:SplitButton.ItemTemplate>
<DataTemplate>
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Margin="5,0,0,0" Text="{Binding FullName}" VerticalAlignment="Center" />
</StackPanel>
</Grid>
</DataTemplate>
</MahApps:SplitButton.ItemTemplate>
</MahApps:SplitButton>
Model for main window:
public partial class MainWindow : MetroWindow
{
public Model data;
public MainWindow()
{
InitializeComponent();
data = new Model();
data.BrowsersAll.Add(new Browser() { FullName = "one" } );
data.BrowsersAll.Add(new Browser() { FullName = "two" } );
data.BrowsersAll.Add(new Browser() { FullName = "three" } );
this.DataContext = data;
}
}
However, moment I try to edit template copy, without making any changes to template it shows errors:
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at WpfApp8splitb.MainWindow.InitializeComponent() in C:\Projects\test\core\WpfApp8splitb\WpfApp8splitb\MainWindow.xaml:line 1
And here is exception error:
ArgumentException: Must have non-null value for 'Setter.Property'.
Link to complete solution file (25.5Kb):
Instead of relying on Visual Studio to decompile the template for you, you could just download the uncompiled version from GitHub.
I belive VS has issues with this kind of triggers with template bindings:
<Trigger SourceName="PART_Expander" Property="IsPressed" Value="True">
<Setter TargetName="PART_Expander" Property="Foreground"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=ArrowPressedBrush, Mode=OneWay}" />
</Trigger>