Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XAML WPF DataGrid wpftoolkit , +
I have created a datagrid which displays a Table of records populating from a Database
& would like to animate the cells of the datagrid when certain condition is met.
For this I created a converter class named **BlinkConverter** that inherits IValueConverter.
 
to put this converter into action, I have mapped the project namespace onto the xaml editor as
 
           xmlns:local="clr-namespace:BlinkApplication"
 
Note: BlinkApplication is the name of my Project
 
After adding this, I am trying to create an instance of my BlinkConvertor class for Binding with Windows.Resources collection as
 
            <Window.Resources>
            <local:BlinkConverter x:key="Blink"></local:BlinkConverter>
            </Window.Resources>
 
here my Intellisense is not detecting the class BlinkCoverter after I type *"local: "* , even if I try to type, I have an error stating "The type local:BlinkConverter was not found. Verify that you are missing an assembly reference and that all referenced assemblies have been built."
 
Even though I have added the entire project under the xmlns in my xaml editor .
What is wrong here ? have I missed any reference ?
Posted 10-Dec-12 0:55am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If you have added the converter and have not built the project, you will get that error. Any new classes you add to the project must be built before they will be picked up by the xaml interpreter.
 
Secondly, make sure you don't have a namespace problem. For example, if you created a behaviors folder and you have the cs file for the behavior in that folder, Visual Studio would have likely put that class at BlinkApplication.Behaviors. Your :local reference will have to match that. Look at the top of the file containing the converter class and see if there is a namespace declaration.
 
The best thing I've found is to add the code for the converter, build the project, then go into the xaml and add the namespace. Intellisense will pop-up the available ones and you can find it in there. That ensures you've got it declared properly.
 
Finally, make sure you declared your converter Public. May seem silly but it won't be available in xaml if you don't.
  Permalink  
Comments
Ind_Pri at 10-Dec-12 12:51pm
   
Do I have to add the Converter class as a part of the MainWindow.xaml.cs class or add a new class naming Converter and then mapping it to the MainWindow.xaml.cs class ?
 
Because on the first try, I added the as a part of Mainwindow.xaml.cs on the first try, then my Intellisense didn't detect, but when I added a separate class as Converter.cs , my Intellisense detects but I dont know the way to map to my Mainwindow.xaml.cs class :(
 
Converter.cs
 
public class Converter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string cellvalue = value.ToString();
return cellvalue = ("Pass");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return false;
}
 
MainWindow.xaml.cs
 
namespace BlinkApplication
{
public partial class MainWindow : Window
{
SqlConnection cn;
SqlDataAdapter da;
DataSet ds;
public MainWindow()
{
InitializeComponent();
DataContext = this;
cn = new SqlConnection(@"Data Source=CZC0239ZWZ\SQLEXPRESS; Initial Catalog =Student; Integrated Security=true");
cn.Open();
}
 
private void Window_Loaded(object sender, RoutedEventArgs e)
{
da = new SqlDataAdapter("select * from dbo.View_StudentResults",cn);
ds = new DataSet();
da.Fill(ds);
dataGrid1.ItemsSource=ds.Tables[0].DefaultView;

}
 
}
}
Jason Gleim at 10-Dec-12 13:51pm
   
Your public class Converter is correct... although I wouldn't call it 'Converter'... something less likely to collide with a keyword is probably a better idea... like "myConverter".
 
So you have MyConverter.cs and in it you have:
 
namespace BlinkApplication.Converters
{
public class myConverter:IValueConverter
{
...
}
}
 
After you add that to the project (as it seems you have done) build the project. You should build successfully. This adds the class into the project at the correct namespace for the xaml interpreter to find it. If you don't do this, you won't get intellisence in xaml and VS will tell you the class doesn't exist.
 
In MainWindow.xaml, you'll add the converter namespace at the top..
xmlns:local="clr-namespace:BlinkApplication.Converters"
Notice that it matches the namespace as declared in the Converters.cs file? That associates the "local" tag with the BlinkApplication.Converters namespace.
 
Once you have done that, you can declare the converter in the page/window/user control resources:



 
Finally... use the converter in the code:
 

 
You should not do anything in the code behind (MainWindow.xaml.cs). Although you CAN assign this stuff in the code behind, it is meant to be declaratively defined in xaml.
Ind_Pri at 11-Dec-12 4:57am
   
Thanks a lot. It worked finally and I got a better understanding..
Cheers :)
-Indhira
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Are you using VS2010? I also experience that sometimes, and check what I am actually missing, but I guess VS is experiencing bug. Try to rebuild and ignore the intellisense it will be recognize later on.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 534
1 Gihan Liyanage 298
2 RyanDev 270
3 Sergey Alexandrovich Kryukov 223
4 Richard Deeming 185
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,771
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100