相关疑难解决方法(0)

无法引用包含合并字典的资源字典

我有一个库,CommonLibraryWpfThemes,里面有几个Resource Dictionary XAML文件.My Themes/Generic.xml文件包含一个ResourceDictionary.MergedDictionaries声明,它将所有其他文件合并在一起.

Generic.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/BrushDictionary.xaml" />
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/TextBlockDictionary.xaml" />
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/LabelDictionary.xaml" />
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/ButtonDictionary.xaml" />
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

在我的应用程序项目中,我引用了CommonLibraryWpfThemes,并在我的App.xaml文件中显式引用了Generic.xml.

App.xaml - 失败

<Application
    x:Class="MyApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/Themes/Generic.xaml" />
    </Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)

这不起作用.运行我的应用程序时出现以下错误:

System.Windows.Markup.XamlParseException occurred
  Message="Cannot find resource named '{_fadedOrangeBrush}'. Resource names are case sensitive.  Error at object 'System.Windows.Setter' in markup file 'CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml' Line 18 Position 13."
  Source="PresentationFramework"
  LineNumber=18
  LinePosition=13
Run Code Online (Sandbox Code Playgroud)

如果我直接将Generic.xaml的内容放入App.xaml,一切正常:

App.xaml - SUCCEEDS

<Application
    x:Class="MyApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary …
Run Code Online (Sandbox Code Playgroud)

wpf xaml themes resourcedictionary

44
推荐指数
3
解决办法
4万
查看次数

多重绑定生成“由于必须指定MultiValueConverter,因此无法设置MultiBinding”

我有一个带有绑定功能的按钮,可以正常工作,请参见下文:

<Button x:Name="licenceFilterSet" Content="Search" Command="{Binding searchCommand}" CommandParameter="{Binding Path=Text, ElementName=licenseTextBox}" />
Run Code Online (Sandbox Code Playgroud)

现在,我意识到我还需要另一条信息,因此我也需要发送a的值check-box。我这样修改了虚拟机:

<Button x:Name="licenceFilterSet" Content="Search" Command="{Binding licenseSearchCommand}">
    <Button.CommandParameter>
        <MultiBinding Converter="{StaticResource searchFilterConverter}">
            <Binding Path="Text" ElementName="licenseTextBox" />
            <Binding Path="IsEnabled" ElementName="regularExpressionCheckBox" />
        </MultiBinding>
    </Button.CommandParameter>
</Button>
Run Code Online (Sandbox Code Playgroud)

以下是我的多转换器:

/// <summary>
/// Converter Used for combining license search textbox and checkbox
/// </summary>
public class SearchFilterConverter : IMultiValueConverter
{
    public object Convert(object[] values)
    {
        return new Tuple<String, bool>((String)values[0], (bool)values[1]);
    }
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么。我收到以下错误,(它指向XAML中的MultiBinding-tag):

Cannot set MultiBinding because MultiValueConverter must be specified.
Run Code Online (Sandbox Code Playgroud)

c# mvvm visual-studio-2010 multibinding

5
推荐指数
1
解决办法
8251
查看次数