C
C#13mo ago
Wicked Cat

✅ How to make a custom converter in .net 6.0 using wpf?

Hello, sorry I couldn't find anything useful using google so i'm asking here, sorry if it's obvious. So i'm trying to make a converter class, but I can't use IValueConverter because System.Windows.Data doesn't exist. When I try making the class without IValueConverter and adding a reference to it in the xaml file it's not found. I'm quite lost but I've read that Windows.Data doesn't work with my version of .net? Thanks everyone for the help
12 Replies
HimmDawg
HimmDawg13mo ago
IValueConverter doesn't exist? Are you sure, you have a reference to the PresentationFramework in your project?
Wicked Cat
Wicked Cat13mo ago
how would I check?
HimmDawg
HimmDawg13mo ago
HimmDawg
HimmDawg13mo ago
Check if this exists ah, mb, the circle needs to be one further down PresentationsFramework is the important thing here
Wicked Cat
Wicked Cat13mo ago
ooh, so I have two projects in my solution, the one the class is in doesn't have it, but the other one does i moved the class over and now I can't return a color lol The name Color does not exist in this context
HimmDawg
HimmDawg13mo ago
Have you included the correct using? You cannot use Color from System.Drawing You need System.Windows.Media In any case. if you want precise help, you gotta show the error and/or some code. Otherwise we are just guessing
Wicked Cat
Wicked Cat13mo ago
Sorry, here's what im getting after adding using System.WIndows.Media
HimmDawg
HimmDawg13mo ago
Yeah, this Color struct doesn't have predefined colors. What you can do instead is taking the color from a Brush, because there are predefined brushes. So instead of Color.Beige, you'll have Brushes.Beige.Color
Wicked Cat
Wicked Cat13mo ago
Alright, thank you for all your help, and sorry this is getting so complex (for me anyways) . If you really wouldn't mind, I just can't figure this out. Here's the whole project: https://github.com/Wicked-Cat/StoryRPG. The relevant folder is StoryRPG, it has the converters folder and the Mainwindow.xaml which I'm trying to use the converter in. StoryRPG has all the xaml files and Engine has everything else, engine is where I tried making the converter class first. What I would like to do is change the background colour of the mainwindow based on a variable in the engine project (specifically the Time class, CurrentTimeOfDay enum)
HimmDawg
HimmDawg13mo ago
You have to use <converters:TimeOfDayToColourConverter ... />
Wicked Cat
Wicked Cat13mo ago
Thank you so much for your help. This way I was trying never even worked but I found a way to do what I want like 100x easier. But I appreciate your patience lol
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts