C# 将样式库加载到WPF中 长问题:
我通过NuGet下载了一个样式库()。 现在我想使用它的样式。坦白地说,这个小任务现在让我发疯了 第一种方法-使用合并: 理想情况下,我会添加如下样式C# 将样式库加载到WPF中 长问题:,c#,wpf,xaml,C#,Wpf,Xaml,我通过NuGet下载了一个样式库()。 现在我想使用它的样式。坦白地说,这个小任务现在让我发疯了 第一种方法-使用合并: 理想情况下,我会添加如下样式 <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary> <BitmapImage x:Key="ImgHelp"
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<BitmapImage x:Key="ImgHelp" UriSource="pack://application:,,,/Resources/Help_32x.png"/>
<!--Lots of our own stuff goes here too-->
</ResourceDictionary>
<ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
并在InitComponent和Run之间调用它
[STAThread]
public static void Main()
{
application.InitializeComponent();
application.LoadSelen();
application.Run();
}
但这再次导致了XamlParseException,但这次是在DataPanel.xaml中,这是一个嵌入到我的主窗口中的面板:
System.Windows.Markup.XamlParseException
HResult=0x80131501
Message = Specifying a value for "System.Windows.Markup.StaticResourceHolder" lead to an excpetion.
Source = PresentationFramework
Stacktrace:
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
Inner Excpetion 1:
FileLoadException: The File or Assembly "System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" or a dependency of it was not found. The found manifestdefinition of the assembly does not match the assembly reference (Excpetion of HRESULT: 0x80131040)
很抱歉格式化不好,不知道如何做得更好。翻译
发生此异常的DataPanel.xaml:
<UserControl x:Class="GUI.DataPanel"
x:Name="UserControlPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<DockPanel LastChildFill="True" Background="Transparent">
<Border DockPanel.Dock="Top" BorderBrush="DarkGray" BorderThickness="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Content="{Binding ElementName=UserControlPanel, Path=HeaderText}" Grid.Column="0" VerticalAlignment="Center"/>
<ItemsControl ItemsSource="{Binding ElementName=UserControlPanel, Path=Items}" Grid.Column="1">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</Border>
<TabControl x:Name="TabControl" ItemContainerStyle="{DynamicResource CollapseSingleTabItem}"/>
</DockPanel>
</UserControl>
简短问题:
如何使用Selen.Wpf中的样式。在这一点上,我几乎不在乎答案有多难看。只要编译和启动(从来没有想过我会在C++世界之外这样说),我就高兴了。 看起来好像是引用了<代码> St.Windows。交互性< /代码>无法解决。 FileLoadException:未找到文件或程序集“System.Windows.Interactivity,Version=4.5.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项。找到的程序集定义与程序集引用不匹配(HRESULT的例外:0x8013100) 看起来nuget包需要这个依赖项,但没有在包描述中指定它。(您可以看到在中添加了对其的引用)
要解决此问题,您可以自己添加对
System.Windows.Interactivity
的引用(并使用第一个解决方案)。您是否尝试添加对System.Windows.Interactivity
的引用?以前没有。现在尝试:不幸的是,两种方法都存在问题。FileLoadException是否相同?在您的建议失败后,我随后删除了引用。为了检查fileloadexpetion
是否仍然相同,我再次添加了它。这次一切顺利。有些按钮甚至是包装的样式。然后,我(再次)删除了引用以进行双重检查。但是在没有裁判的情况下,尽管有各种各样的可能性,它仍然可以工作?重新启动VS并清洁溶液-仍然可以工作。但这与上面发布的代码完全相同。我不明白这是真的。需要补充的是,您需要引用正确的版本。看起来我一开始用的是4.0,但Selen需要4.5。这导致了我的很多困惑,因为在VS的ProjcetExplorer中看不到该版本。谢谢你帮助我!
<UserControl x:Class="GUI.DataPanel"
x:Name="UserControlPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<DockPanel LastChildFill="True" Background="Transparent">
<Border DockPanel.Dock="Top" BorderBrush="DarkGray" BorderThickness="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Content="{Binding ElementName=UserControlPanel, Path=HeaderText}" Grid.Column="0" VerticalAlignment="Center"/>
<ItemsControl ItemsSource="{Binding ElementName=UserControlPanel, Path=Items}" Grid.Column="1">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</Border>
<TabControl x:Name="TabControl" ItemContainerStyle="{DynamicResource CollapseSingleTabItem}"/>
</DockPanel>
</UserControl>