简体   繁体   中英

Can't declare an object as resource

I want to declare a class from my code-behind as a resource in XAML.

Here is my XAML:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication1"
    Title="ConverterSample" Height="140" Width="250">
    <Window.Resources>
        <local:YesNoToBooleanConverter x:Key="YesNoToBooleanConverter" /> //Here I get my error 
    </Window.Resources>
</Window>

I defined a namespace in XAML but somehow it does not find YesNoToBooleanConverter in my resources.

YesNoToBooleanConverter is defined like this in my code behind:

using System;
using System.Windows;
using System.Windows.Data;

namespace WpfApplication1
    {
        public partial class MainWindow : Window
        {
             public MainWindow()
             {
                    InitializeComponent();
             }
        }

        public class YesNoToBooleanConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                //Some code
            }

            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                //some code
            }
        }
    }

I tried everything, but I can´t figure out my mistake.

Solution:
Rebuild the entire project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM