默认复制模板上的 MahApps Metro SplitButton 错误
MahApps Metro SplitButton error on default copy template
已在 .Net Core 3.1 中创建了空白 WPF 应用程序,添加了 MahApps Metro 包 2.0.0。添加了简单的 SplitButton 并实现了简单的 ViewModel 以在 SplitButton 中显示项目。这很好用。
拆分按钮XAML代码:
<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>
主要模型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;
}
}
但是,当我尝试编辑模板副本时,没有对模板进行任何更改,它显示错误:
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
这是异常错误:
ArgumentException: Must have non-null value for 'Setter.Property'.
Link 完成解决方案文件 (25.5Kb):
您可以 download the uncompiled version from GitHub.
而不是依靠 Visual Studio 为您反编译模板
我认为 VS 对这种带有模板绑定的触发器存在问题:
<Trigger SourceName="PART_Expander" Property="IsPressed" Value="True">
<Setter TargetName="PART_Expander" Property="Foreground"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=ArrowPressedBrush, Mode=OneWay}" />
</Trigger>
已在 .Net Core 3.1 中创建了空白 WPF 应用程序,添加了 MahApps Metro 包 2.0.0。添加了简单的 SplitButton 并实现了简单的 ViewModel 以在 SplitButton 中显示项目。这很好用。
拆分按钮XAML代码:
<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>
主要模型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;
}
}
但是,当我尝试编辑模板副本时,没有对模板进行任何更改,它显示错误:
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
这是异常错误:
ArgumentException: Must have non-null value for 'Setter.Property'.
Link 完成解决方案文件 (25.5Kb):
您可以 download the uncompiled version from GitHub.
而不是依靠 Visual Studio 为您反编译模板我认为 VS 对这种带有模板绑定的触发器存在问题:
<Trigger SourceName="PART_Expander" Property="IsPressed" Value="True">
<Setter TargetName="PART_Expander" Property="Foreground"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=ArrowPressedBrush, Mode=OneWay}" />
</Trigger>